ASP. NET MVC Ajax

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.