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.