2012-08-15 47 views
4

在我的Razor视图我有以下几点:Html.BeginForm后要HTTPGET行动,而不是HttpPost在IE中,罚款Chrome和Firefox

@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开发人员工具控制台中没有任何线索。

任何明显的,我失踪?

+0

你可以发布表单的呈现HTML吗? – Andrei 2012-08-15 08:49:44

回答

5

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

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

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

看到这个SO问题的进一步差异:Difference between <input type='button' /> and <input type='submit' />

+0

谢谢你,我已经试过了,但我有同样的问题 – 2012-08-15 09:02:15

+0

@DeclanMcNulty奇怪它应该工作......是否有任何JavaScript参与表单提交?你可以发布呈现的HTML吗? – nemesv 2012-08-15 09:08:34

+0

感谢您的回答@nemesv,您对JavaScript的正确性。我在提交按钮上有一个点击事件,根据页面上的其他条件有条件地提交表单。这是使用$('form')来选择表单,IE将这个解释为整个表单,而不是我上面代码中的那个。我重构了我的代码,为表单提供了一个ID并使用了一个proer提交按钮 – 2012-08-15 09:18:52

相关问题