O'Reilly logo

Professional ASP.NET MVC 3 by K. Scott Allen, Brad Wilson, Phil Haack, Jon Galloway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. Because you might be using this functionality in a number of places in the application, you can include this file in the layout view (after including jQuery).

<script src="@Url.Content("∼/Scripts/jquery-1.4.4.min.js")" 
        type="text/javascript"></script>    
<script  src="@Url.Content("∼/Scripts/Scripts/jquery.unobtrusive-ajax.min.js")"
         type="text/javascript"></script>
@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 (but 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required