mvc-implementing AJAX+MVC Asynchronous Fetch data

Source: Internet
Author: User

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

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.