Ajax Helpers

You've seen the HTML helpers in ASP.NET MVC. You can use the HTML helpers to create forms and links that point to controller actions. There is also a set of Ajax helpers in ASP.NET MVC. Ajax helpers also create forms and links that point to controller actions, but they behave asynchronously. When using these helpers, you don't need to write any script code to make the asynchrony work.

Behind the scenes, these Ajax helpers depend on the unobtrusive MVC extensions for jQuery. To use the helpers, you need to have the jquery.unobtrusive-ajax script present. Note that a default MVC 4 project will include this script in the application's _Layout view by default. If you want to include the file manually, you could use the following script tags:

<script src="∼Scripts/jquery-1.6.2.min.js")
<script  src="∼/Scripts/Scripts/jquery.unobtrusive-ajax.min.js")

@RenderSection("scripts", required:false);

Ajax ActionLinks

Ajax helpers are available through the Ajax property inside a Razor view. Like HTML helpers, most of the methods on this property are extension methods (except for the AjaxHelper type).

The ActionLink method of the Ajax property creates an anchor tag with asynchronous behavior. Imagine you want to add a “daily deal” link at the bottom of the opening page for the MVC Music Store. When users click the link, you don't want them to navigate to a new page, but you want the existing page to magically display the details of a heavily discounted album. ...

Get Professional ASP.NET MVC 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.