Nur*_*ihu 2 html asp.net-mvc asp.net-mvc-4
我在提交表单时调用 POSt 控制器方法时遇到问题。下面是我的两种方法
[HttpGet]
public ViewResult List(int page = 1)
{
}
[HttpPost]
public ViewResult List(SearchTerms search,int page = 1)
{
}
Run Code Online (Sandbox Code Playgroud)
在 http 请求中,我的 GET 方法按照我的需要被调用。但是,当我提交表单时,我期望调用 POST 方法,但再次调用相同的 GET 方法。post 方法永远不会被调用。请问我哪里出错了?任何帮助都值得赞赏。下面是我的表格。
@using (Html.BeginForm("List", "Search",
FormMethod.Post, new { @class="form-group text-right" }))
{
......
<span class="input-group-btn">
<button class="btn btn-info" type="button" id="addressSearch" onclick="location.href='@Url.Action("List", "Search")'">Search</button>
</span>
...
}
Run Code Online (Sandbox Code Playgroud)
您的按钮不会提交表单。它重定向回列表页面,这使得浏览器发送 GET 请求。您可以使按钮提交表单:
@using (Html.BeginForm("List", "Search",
FormMethod.Post, new { @class="form-group text-right" }))
{
......
<span class="input-group-btn">
<button class="btn btn-info" type="submit" id="addressSearch">Search</button>
</span>
...
}
Run Code Online (Sandbox Code Playgroud)