【问题标题】:Html.BeginForm Post going to HttpGet action rather than HttpPost in IE, fine in Chrome and FirefoxHtml.BeginForm Post 去 HttpGet 操作而不是 IE 中的 HttpPost,在 Chrome 和 Firefox 中很好
【发布时间】:2012-08-15 16:52:41
【问题描述】:

我的 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>

}

在我的控制器中我有

[HttpGet]
public virtual ActionResult Edit(string id)
{
}

[HttpPost]
public virtual ActionResult Edit(ViewModel viewModel)
{
}

在 Firefox 和 Chrome 中一切正常,但在 IE 中,提交表单时触发的是 HttpGet 操作而不是 HttpPost。

调用堆栈或 IE 开发者工具控制台中没有任何线索。

我遗漏了什么明显的东西?

【问题讨论】:

  • 你可以为表单发布渲染的 html 吗?

标签: c# asp.net-mvc-3 razor


【解决方案1】:

您的提交按钮应该是真正的submit buttontype="Submit"

<input id="btnSubmit" type="submit" value="Submit" />

在所有浏览器中正确提交表单。

有关更多差异,请参阅此 SO 问题:Difference between <input type='button' /> and <input type='submit' />

【讨论】:

  • @DeclanMcNulty 奇怪它应该可以工作......表单提交中是否涉及任何 JavaScript?你能发布渲染的html吗?
  • 感谢您的回答@nemesv,您对javascript的看法是正确的。我在提交按钮上有一个点击事件,它根据页面上的其他一些条件有条件地提交表单。这是使用 $('form') 来选择表单,而 IE 将其解释为整个表单,而不是我上面代码中的表单。我已经重构了我的代码,为表单提供了一个 ID 并使用了更正确的提交按钮
猜你喜欢
  • 2012-10-21
  • 2010-11-06
  • 2016-02-05
  • 2010-09-21
  • 1970-01-01
  • 2011-08-03
  • 1970-01-01
  • 2012-07-30
  • 1970-01-01
相关资源
最近更新 更多