Lot*_*tuX 2 forms jquery asp.net-mvc-3
我尝试将Jquery中的表单提交给Controller中的Action方法.为此,我序列化我的表单并使用get方法.在控制器中,我接收我的表单作为字符串,如param1 = 1¶m2 = 2 ....有没有办法直接检索我的Action方法中的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");
});
Run Code Online (Sandbox Code Playgroud)
我的形式在这里:
@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>
}
Run Code Online (Sandbox Code Playgroud)
这是我的行动方法:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CheckSelection(string clientId, string policyId, string countryCode, string month, FormCollection formCollection){}
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助!
var form = $("#CheckForm");
var formCollection = form.serialize();
$.post('@Url.Action("CheckSelection")', formCollection , function (data) {
alert(data); //will alert form submitted
});
Run Code Online (Sandbox Code Playgroud)
控制器看起来像
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CheckSelection(FormCollection collection){
return Content("form submitted");
}
Run Code Online (Sandbox Code Playgroud)
有关FormCollection类的详细信息,请单击此链接
| 归档时间: |
|
| 查看次数: |
7243 次 |
| 最近记录: |