MVC中的表单发布操作不会触发控制器中的操作

问题描述 投票:0回答:1

我只是在.cshtml中有此内容:

                <div class="col-xs-8 col-xs-offset-2">
                    @*<form action="@Url.Action("SaveSubstitutes", "Preferences")" method="post">
                        <button type="submit" form="PreferencesForm">Save</button>
                    </form>*@
                    }
                </div>

但是动作未在PreferencesController中被击中

        [HttpPost]
        public ActionResult SaveSubstitutes(PreferencesViewModel vm)
        {
            return "test"
        }
c# forms model-view-controller action
1个回答
0
投票

也许在div关闭后加上}

         <div class="col-xs-8 col-xs-offset-2">
                @*<form action="@Url.Action("SaveSubstitutes", "Preferences")" method="post">
                    <button type="submit" form="PreferencesForm">Save</button>
                </form>*@

            </div>
             }     

和/或删除评论部分

© www.soinside.com 2019 - 2024. All rights reserved.