As follows:
1: Non-Ajax
Front desk:
Corresponding background:
Ajax of 2:jquery
Before introducing the use of jquery to submit a form, we need to first refer to Jquery.form.js, which comes from http://www.malsup.com/jquery/form/, so we need to refer to the JS file:
Functional Requirements: Ajax submits the form, handles the request in the controller Helloworld4controller, and returns a number of data formatted as JSON.
First, we assume that the returned JSON entity is:
Copy Code code as follows:
public class Loginresultdto
{
public bool Success {get; set;}
public string Message {get; set;}
public string ReturnUrl {get; set;}
}
The code for the Controller section is:
Copy Code code as follows:
public class Helloworld4controller:controller
{
Public ActionResult Index ()
{
if (Request.isajaxrequest ())
{
String str1 = request.form["Text33"];
String str2 = request.form["Text44"];
Return Json (new MvcApplication5.Controllers.HelloWorld3Controller.LoginResultDTO {Success = true, message = str1 + str2, ReturnUrl = "Someurl"});
}
Else
{
return View ();
}
}
}
The code above tells us that it is also convenient if we want to return to another entity.
Front Section code:
If the button does not use submit, the image above is changed to the following form:
SOURCE Download: Mvcapplication5.zip