我尝试将 Jquery 中的表单提交到控制器中的 Action 方法。
为此,我序列化我的表单并使用 get 方法。在控制器中,我收到像 param1=1¶m2=2... 这样的字符串形式的表单。
有没有办法在我的操作方法中直接检索 FormCollection 而不是字符串。由于我的表单有很多复选框,因此我可以更轻松地将其放入 formCollection 中。
这是我的 Jquery:
var form = $("#CheckForm");
var formCollection = form.serialize();
$.post('@Url.Action("CheckSelection")', { clientId: clientId, policyId: policyId, countryCode: country, month: monthtoken[0] + '*' + monthtoken[1], formCollection: formCollection }, function () {
alert("formSubmit");
});
这是我的表格:
@using (Html.BeginForm("CheckSelection", "Check", FormMethod.Post, new { id = "CheckForm" }))
{
<fieldset>
<div class="editor-label">
@Html.CheckBox("CodeExist",true)
@Html.Label("Check Code Existence")
</div>
<div class="editor-label">
@Html.CheckBox("Mandatory",true)
@Html.Label("Check Code Reccurence")
</div>
<div class="editor-label">
@Html.CheckBox("Reccurence",true)
@Html.Label("Check Mandatory Code")
</div>
}
这是我的行动方法:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CheckSelection(string clientId, string policyId, string countryCode, string month, FormCollection formCollection){}
在此先感谢您的帮助!