Adding AJAX support for the ASP.net MVC framework

Source: Internet
Author: User

First, the introduction

In this article, we'll show you how to add some basic AJAX features (such as local updates and behavioral components) to ASP.net applications built on the ASP.net MVC framework.

"description" This article provides you with a complete application source code and test example for the ASP.net MVC framework. In this scenario, there are two projects: one is tasklist (Web application) and the other is AJAXMVC (a class library that provides extended AJAX support). Note that the functions provided in class library AJAXMVC implement some basic AJAX features, such as local updates that are not dependent on page postbacks, and extensions that are similar to the behavior in asp.net ajax frameworks (Behavior) that are associated with DOM elements. In fact, the latest ASP.net MVC framework version (Preview 4) already provides out-of-the-box AJAX support capabilities. So, you can take the functionality provided here as an early asp.net MVC framework version of the experiment.

Second, the construction of Simple task column representation program

To focus on the topic of this article in order to simplify the surface of the problem, a basic Task List case application is provided in this article. Although this program is very simple, it lets us focus on the AJAX features that we are more interested in. The following is a snapshot of the running time for the sample application in this article.

For a classic introductory tutorial on the MVC framework, please refer to Scott Guthrie's blog (http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc- framework-part-1.aspx). We don't want to repeat it here, but like the product catalog application provided by Scott Guthrie, this tasklist application in this article uses a controller to process requests from clients, using a set of classes to form a model that describes a set of task items. There is also a set of views to build the user interface.

First, before you start adding some Ajax features to the example, let's analyze the basic composition of the sample application in this article.

(i) model

Let's first analyze the model section of this example, which consists of the following two parts:

public class Task {
public int ID { get; }
public bool IsComplete { get; set; }
public string Name { get; set; }
}
public interface ITaskDB {
Task AddTask(string name);
void CompleteTask(Task task);
Task GetTask(int taskID);
ICollection<Task> GetTasks();
void RemoveTask(Task task);
}

The code here doesn't mean much. Note, however, that in this case, in order to simplify the problem, I used an in-memory dataset to simulate the task list data (instead of using the database sample).

Also, it is necessary to mention that the interface (ITASKDB) method is used here to facilitate the addition of test code (discussed later).

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.