ASP. net mvc Ajax call

Source: Internet
Author: User

In ASP. net mvc beta, we can use Ajax. beginform and Ajax. actionlink for Ajax calls. We can also use some Ajax frameworks such as jquery to simplify Ajax calls.

1. ASP. net mvc Beta has built-in Ajax support, but we must introduce microsoftajax. JS, micorsoftmvcajax. js.

2. Because ASP. net mvc has integrated jquery, we can also easily use jquery's Ajax function.

OfCodeDemonstrate three front-end Methods

(1) Ajax. beginform

How to append parameters outside of the form to remote connection is involved here. In fact, we only need to append the parameters to the Post URL, for example, changing the action to ajaxgetjson? Name = Jack, or ajaxgetjson/Jack, and then Configure route.

(2) Ajax. actionlink

The additional parameters are the same as those above.

(3) jquery. Ajax

See the getbyjquery () function.

3. Background code

The first one directly returns JSON data, the second one, and the third one returns HTML data through the user control.

 

Public JsonresultAjaxgetjson (PersonP)

{

Thread. Sleep (3000 );

Return This. JSON (P );

}

 

Public ActionresultAjaxgetstring ()

{

PersonP =New Person{Firstname ="Bill", Lastname ="Gates"};

ReturnView ("Ajaxcontent", P );

}

 

Public ActionresultAjaxbyjquery ()

{

PersonP =New Person{Firstname ="Bill", Lastname ="Gates"};

ReturnView ("Ajaxcontent", P );

}

 

4. ajaxcontent user control content

 

Through the above method, we can easily imitate the original WebService call and put Ajax functions in a unified controller, such as ajaxservicecontroller.

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.