Change form submission in ASP. NET MVC to Ajax commit
The form form submission code generated by the @using (Html.BeginForm ()) in the ASP. NET MVC view can intercept the form submission with JavaScript code, instead of the Ajax commit, the sample code is as follows:
Code from: http://www.cnblogs.com/dudu/archive/2011/12/07/asp_net_mvc_form_ajax.html
$ (' #form1 '). Submit (function () {
if ($ (this). Valid ()) {
$.ajax ({
Url:this.action,
Type:this.method,
Data: $ (this). Serialize (),
Success:function (Result) {
$ (' #result '). HTML (result);
},
Error:function (Result) {
alert (result);
}
});
}
return false;
});
Or
$.Ajax({
Type: "POST",
Url:'/iteminfo/edititem ',Corresponds to Controllername/actionname
Timeout: 3000,
data: $("#fm"). Serialize(), //{partnumber: ' $ ', Project: ' Project ', Family: ' Chord '}, /c4>
Error: function () {Alert(' failed! '); },
Success: function (data, textstatus) {
$(' #Planner_ItemInfo '). DataGrid(' LoadData ', data);
}
});
The ajax.beginform with ASP. NET MVC can also implement AJAX submissions, but the control of the returned results is not flexible, the code is as follows:
@using (Ajax.beginform (new ajaxoptions {httpmethod = "POST", Updatetargetid = "Result"})
ASP. NET MVC Ajax