Home/MVC/Ajax Helpers in ASP.NET MVC

Ajax Helpers in ASP.NET MVC

Ajax Helpers:

We already aware that we use HTML helpers to create a forms with the user’s controls. ASP.NET MVC provides another option that is Ajax helpers functionality to our web applications. The main purpose of AJAX Helpers are used to create AJAX enabled forms and links which performs request asynchronously.

When to use?

Here big question will raise, both HTML helper and AJAX helper method generate the anchor tag then why we need to use the @AJAX.ActionLink instead of @HTML.ActionLink ? The solution will be,

  • When the user clicks on the link and it want to redirect to another page then we can use @HTML.ActionLink.
  • When the user clicks on the link and don’t want to redirect to different page, need to stay on the same page (without Post Back), then we can go for @AJAX.ActionLink.

Difference between Html and Ajax helper:

  • HTML helper class performs request synchronously.
  • Ajax helper class performs request asynchronously.

Namespace: System.Web.Mvc

Unobtrusive AJAX

ASP.NET MVC supports unobtrusive Ajax which is based on jQuery. The unobtrusive Ajax is used to define the Ajax features through in our application. While creating project in ASP.NET MVC, the jquery-unobtrusive-ajax.js and jquery-unobtrusive-ajax.min.js files has added automatically to our application as shown below.

Ajaxhelper- unobtrusive-dotnet-helpers

Ajax helper Properties and its use :

UrlSpecify the URL that will be requested from the server.
ConfirmGiven message will be displayed in a confirm dialog to the end user.The ajax call will trigger after clicked OK button
OnBeginThe javaScript function name in OnBegin will be intiated at the BEGINNING of the Ajax request.
OnCompleteThe javaScript function name in OnComplete will be intiated at the END of the Ajax request.
OnSuccessThe javaScript function name in OnSuccess will be intiated when Ajax request succeed.
OnFailureThe javaScript function name in OnFailure will be intiated when Ajax request failed
UpdateTargetIdSpecify the target container’s Id that will be populated with the HTML returned by the action method.
InsertionModeSpecify the way of populating the target container. The possible values are InsertAfter, InsertBefore and Replace (which is the default).
LoadingElementIdSpecify progress message container’s Id to display a progress message to the end user while processing the Ajax request.
LoadingElementDurationSpecify a time duration for controls the duration of the progress message during the Ajax request.

Example 1 : With Simple Ajax call

Below example code shows how to use AJAX action link in Asp.Net MVC.


Run the application and  we can see that the he ajax helper Action link has converted to the HTML anchor link element as shown below.

<a data-ajax=”true” data-ajax-method=”GET” data-ajax-mode=”replace” data-ajax-success=”fnSuccess” data-ajax-update=”#divGetAllUsers” href=”/Ajaxhelpers/GetDetails”>Get User Details</a>


Example 2 : With “Confirm” properties



Run the application and click the “Get User Details”, then it will show the pop up for confirmation to proceed. If u click “Ok” then it will process the Ajax request. If we click “cancel” then it wont process the Ajax request.

Ajax Helper call with Confirmation msg - dotnet-helpers


The following things need to be required before using ajax helper class.

Required reference:

Required Configuration:

One Comment

  1. Bhupender July 12, 2016 at 3:30 pm

    Thank you very much for all your articles, you have provided a lot of useful information on jquery and MVC.

Leave a Reply