UpdatePanel for asp.net mvc attempt

Source: Internet
Author: User

In fact, this is a late release of nearly 2 months of the article. In fact, I've prepared all the content of this article before the ASP.net MVC Preview 2 release. At that time, I would like to preview 2 release it, and really once preview 2 released but did not bother to transplant-after the transplant but did not bother to write articles. This drag is nearly 2 months, no progress. Maybe work and other things are really a little more, but ask yourself, also not busy. Time is often wasted in dribs and drabs. Alas, it may be that the ego is too high and less willing to write ordinary introductory articles, leading to a significant reduction in what can be written. But then again, actually intend to write, and even said to write a lot of things are not little, why is not to pen? In fact, is still a "lazy" word-the diligence of that year where to go?

Anyway First explain the title, what is "UpdatePanel for asp.net MVC"? asp.net Ajax UpdatePanel believe that we all know something. Unfortunately, the birth of the ASP.net MVC framework "destroys" a large number of postback based controls, and the first is likely to be UpdatePanel. If you don't have postback,updatepanel, you lose all of your action, or even some bound controls, at least they can be used for presentation. After UpdatePanel Changxuduantan, we can not help but begin to miss the advantage of UpdatePanel: "Transparent." With the help of UpdatePanel, Ajax operations are almost completely transparent to developers. All we have to do is wrap the content that needs Ajax updates with UpdatePanel, and everything is so elegant.

Can we save UpdatePanel in asp.net mvc? It may be possible, but it's more like an "impossible task". I'm not a legendary Tom, so it seems more feasible to tailor an AJAX solution for ASP.net mvc. Although we do not expect a new thing to be perfect from the beginning, but even if it is only a prototype, it must strictly adhere to some of the principles:

Not to break the agreement in MVC (collaboration, responsibility, etc.)

Be as transparent to the developer as possible

Nikhil Kothari once presented his Ajax solution under the asp.net MVC framework. If you don't know what he's doing, I'll start with a little generalization here. Nikhil extends controller to support an AJAX operation, so we can write the following code in code:

public class TaskListController : AjaxController {
   ...
  public void CompleteTask(int taskID) {
    if (String.IsNullOrEmpty(Request.Form["deleteTask"]) == false) {
      InvokeAction("DeleteTask");
       return;
    }
    Task task = _taskDB.GetTask (taskID);
    if (task != null) {
       _taskDB.CompleteTask(task);
    }
    if (IsAjaxRequest) {
      if (task != null) {
         RenderPartial("TaskView", task);
      }
    }
    else {
      RedirectToAction ("List");
    }
  }
  ...
}

Similar to Ajaxcontroller, Nikhil also provides some extension methods for ViewPage and Viewcontrol, so we can see the following code in view (list.aspx) Now:

<div id="taskList">
  <% foreach (Task task in Tasks) { %>
    <div>
      <% this.RenderPartial("TaskView", task); %>
     </div>
  <% } %>
</div>

Related Article

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.