The server-side implementation principle is not complicated, but as another key part of the solution, how to trigger an AJAX submission on the client is also a worthwhile topic to consider. UpdatePanel's way can be described as "fully automatic": the page load will be the server side of the trigger information output to the client, and then intercept the form on the client side of the event, and through the UniqueID or DOM structure, and other ways to determine whether the submission should be converted to Ajax mode. However, in a asp.net mvc page there is almost no element that produces postback, instead there is a large number of common links, which are the main intercept targets for AJAX updates.
For this I have provided some JavaScript code that intercepts a link's original destination address and translates it into an AJAX request. I'm here to show this usage through the code in the example (this example is derived from the ASP.net MVC example provided by Brad Abrams, but I've discarded the Northwind database and the entity Framework. Instead, the XML data and the custom simple model. In addition, I also ported it to the 0416 build of the asp.net MVC framework:
<% foreach (var category in this.ProductCategories)
{ %>
<li>
<%= Html.ActionLink<ProductsController>(
c => c.List(category, 1),
category,
new { onclick = "mvcAjax.get(this, event)" })%>
</li><%
} %>
This code comes from the Category List page. The only difference is that the OnClick event (bold part) of the element is specified in addition to the code before the Ajax improvement. In the onclick event execution, this link default jump behavior will be canceled, instead of an AJAX request, the target is the ProductsController named List action.
We can use the above method to deal with the normal link, then how to make a client from the commit behavior also become Ajax operation? The following is still the code in the example:
<form method="post"
action="<%= Url.Action("Update", new { id = this.Product.ProductID }) %>"
onsubmit="mvcAjax.submit(this, event);">
<table>
<tr>
<td>Name:</td>
<td><%= Html.TextBox("Name", this.Product.Name) %></td>
</tr>
</table>
<input type="submit" value="Save" />
</form>