2
我有一個Asp.Net MVC 3應用程序,當我點擊我的提交按鈕後,我想驗證在formcollection參數中傳遞的信息..如果它無效,我返回一個JSON ..但在那之後我的FormCollection總是返回nullAsp.Net MVC 3 formcollection提交後丟失數據
這種情況發生在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"
});
}
你將如何使用迭代的List值?強類型模型不支持List <>值。這就是爲什麼沒有選項必須使用FormCollection。 – ajayDevgan 2012-07-02 13:21:08