Before the combination of Ajax and general processing program to achieve the data exchange between the front and back of the blog, now do the system to use the MVC, but also used to get data asynchronously. The ajax+ general handler is the same as the Mvc+ajax principle, which is the name of the generic handler written in the "URL", which writes to the method that the controller needs to invoke.
Design in a controller
Using system.collections.generic;using system.web.mvc;namespace mvcajaxbyajax.controllers{ //Exam Questions public Class examentity {public int Id {get; set;} public string Examname {get; set;} } public class Mvcajaxbyajaxcontroller:controller { [HandleError] public actionresult Index () { return View (); } <summary>///access to test data//</summary>// <returns></returns> [ HttpPost] public actionresult Getexam () { //Add Employee data list<examentity> examlist = new List<examentity> () { new examentity {id = 1, examname = "Language Test"}, new examentity {id = 2, examname = " Math Test "} }; Returns the JSON type return JSON directly (examlist);}}}
Design in the View
@{viewbag.title = "Index";} <script src= "~/scripts/jquery-2.1.3.min.js" ></script>
View the returned data through Firebug
Page Display effect
Summarize
Using Mvc+ajax to implement the query of asynchronous data, call the controllers method of the background directly, and return the data to the foreground control directly by the background method.
mvc-implementing AJAX+MVC Asynchronous Fetch data