我有一个 Asp.Net MVC 3 应用程序,单击提交按钮后,我想验证 formcollection 参数中传递的信息.. 如果它无效,我返回一个 jSon.. 但之后我的 formcollection 总是返回 null
这发生在 chrome 和 FFox 中。在 IE 中它工作正常
我的观点:
<li id="opc-register" class="section allow">
<div id="checkout-step-register" class="step a-item" style="display: none;">
<form id="co-register-form" action="">
<div id="checkout-register-load">
@Html.Action("OpcRegisterForm", "Checkout")
</div>
</form>
<script type="text/javascript">
Register.init('#co-register-form', '@(storeLocation)checkout/OpcSaveRegister/');
</script>
<div class="buttons" id="register-buttons-container">
<button type="button" class="paymentmethodnextstepbutton" onclick="Register.save()">
<span>@T("Common.Continue")</span>
</button>
<span class="please-wait" id="register-please-wait" style="display: none;">
<img src="@Url.Content("~/Content/Images/ajax_loader_small.gif")"
alt="@T("Common.LoadingNextStep")" title="@T("Common.LoadingNextStep")" />
@T("Common.LoadingNextStep")</span>
</div>
</div>
</li>
我的控制器
[HttpPost]
public ActionResult OpcSaveRegister(FormCollection form)
{
var registerModel = PrepareRegisterModel();
registerModel.Email = form["Email"];
registerModel.FirstName = form["FirstName"];
...
if (TryValidateModel(registerModel))
{
....
}
//If we got this far, something failed, redisplay form
return Json(new
{
update_section = new UpdateSectionJsonModel()
{
name = "register",
html = RenderPartialViewToString("OpcRegister", registerModel)
},
goto_section = "register"
});
}