How to Use ajax in the asp.net mvc project?

Source: Internet
Author: User

The official CTP version of ASP. net mvc framework does not include AJAX support. However, several examples show how to add AJAX for ASP. net mvc applications.

Example:

Public class TaskListController:AjaxController{
Public void Add (string name ){
Task newTask = null;
If (String. IsNullOrEmpty (name) = false ){
NewTask = _ taskDB. AddTask (name );
}
If (IsAjaxRequest ){
If (newTask! = Null ){
RenderPartial ("TaskView", newTask );
}
}
Else {
[...]
}
}
}

AjaxaController is a Class I added. It introduces a new attribute IsAjaxRequest. I can use it in the Action method to do something like output different views. It also introduces other members, such as the RenderPartial method, which can generate a part of the user interface by defining the content in a partial view instead of a complete page. The following is my new Controller and the new Add method. In addition to Controller extensions, Nikhil also provides some extension methods for the view to use: "RenderBeginForm is used to generate a common Form label, renderBeginAjaxForm generates an AJAX available Form [...], and the rendform method ". This example shows the first step of using the core AJAX functions of ASP. NET pages-partial refresh, Behaviors, and Extender controls ".

 

Http://www.infoq.com/news/2007/12/ajax-aspnet-mvc;jsessionid=F7AFF0755D7AE56F7F63196D748BFC1B.

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.