I try to submit a form in Jquery to an Action method in a Controller.
To do so I serialize my form and use the get method. In the controller I receive my form as a string like param1=1¶m2=2….
Is there a way to retrieve directly a FormCollection in my Action Method instead of the string. As my form has many checkboxes it will be easier for me to have it in formCollection.
Here is my 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");
});
Here my form:
@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>
}
Here is my Action Method:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CheckSelection(string clientId, string policyId, string countryCode, string month, FormCollection formCollection){}
Thanks in advance for your help!
and the controller will look like
for details of the FormCollection class follow this link