C# Html.BeginForm Post 在 IE 中转到 HttpGet 操作而不是 HttpPost,在 Chrome 和 Firefox 中很好
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11966345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Html.BeginForm Post going to HttpGet action rather than HttpPost in IE, fine in Chrome and Firefox
提问by Declan McNulty
I have the following in my Razor view:
我的 Razor 视图中有以下内容:
@using (Html.BeginForm("Edit", "MyController", FormMethod.Post))
{
<div class="grid_1"> </div>
<div id="ValSummary"> @Html.ValidationSummary(false)</div>
@Html.EditorFor(x => x.Role, MVC.Shared.Views.EditorTemplates.KeyValuePairSelectList, new { SelectListOptions = Model.RoleSelectList })<br /><br />
@Html.EditorFor(x => x.Trust, MVC.Shared.Views.EditorTemplates.KeyValuePairSelectList, new { SelectListOptions = Model.TrustSelectList.OrderBy(x => x.Text) })<br /><br />
@Html.EditorFor(x => x.GmcCode)<br /><br />
<div class="createbutton">
<input id="btnGoBack" type="button" value="Back"/>
<input id="btnSubmit" type="button" value="Submit" />
</div>
}
In my controller I have
在我的控制器中,我有
[HttpGet]
public virtual ActionResult Edit(string id)
{
}
[HttpPost]
public virtual ActionResult Edit(ViewModel viewModel)
{
}
In Firefox and Chrome everything works fine but in IE when the form is submitted the HttpGet action is being fired rather than the HttpPost.
在 Firefox 和 Chrome 中,一切正常,但在 IE 中,当提交表单时,将触发 HttpGet 操作而不是 HttpPost。
There are no clues in the call stack or from the IE developer tools console.
调用堆栈或 IE 开发人员工具控制台中没有任何线索。
Anything obvious that I am missing?
有什么明显的我失踪了吗?
采纳答案by nemesv
Your Submit button should a real submit buttonwith type="Submit"
您的提交按钮应该真正的提交按钮与type="Submit"
<input id="btnSubmit" type="submit" value="Submit" />
to submit the form correctly in all browsers.
在所有浏览器中正确提交表单。
See this SO questions for further differences: Difference between <input type='button' /> and <input type='submit' />
请参阅此 SO 问题以了解更多差异:Difference between <input type='button' /> and <input type='submit' />

