简体   繁体   English

Html.BeginForm在IE浏览器中发布HttpGet动作而不是HttpPost,在Chrome和Firefox中很好

[英]Html.BeginForm Post going to HttpGet action rather than HttpPost in IE, fine in Chrome and Firefox

I have the following in my Razor view: 我的Razor视图中有以下内容:

 @using (Html.BeginForm("Edit", "MyController", FormMethod.Post))
{
    <div class="grid_1">&nbsp;</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? 我遗失的任何明显的东西?

Your Submit button should a real submit button with 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问题以获得进一步的差异: <input type ='button'/>与<input type ='submit'/>之间的差异

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM