I hope you have basic knowledge of the HTML helper method available in ASP.NET MVC . If you have no idea about the HTML helper method, I recommend you to go through the HTML helper before proceeding through this article.
You know that MVC framework supports AJAX features. Like the HTML helper method ASP.NET MVC has a AJAX helper. Both the HTML helper method and AJAX helper method are used to create the HTML markup. These methods generate the form tag and anchor tag that points to the controller action method. But the main difference is that the HTML helper calls the controller action method synchronously (i.e entire page refresh) while the AJAX helper calls asynchronously (I.e just refresh the portion of page that display updated info).
To get AJAX helper support in your project, you must have jquery.unobstrusive.ajax.js script library in your project.You can get this library via NuGet package manager console or NuGet package dialog.
There are two ways to install jquery.unobstrusive.ajax.js library into your project.
Option 1: Install via NuGet package manager console
Open Visual Studio, Tools, NuGet Package Manager, then click Package Manager Console and perform the following command on NuGet console.
Install-Package jquery.unobstrusive.ajax.js
Option 2: Install via NuGet package dialog.
Right click on project name in solution explorer and go to Manage NuGet Packages option.
Now search for the following term Microsoft.jQuery.Unobtrusive.Ajax. Click on install button.
When you perform these commands visual studio will add two java script file in your project Scripts folder.
After adding this script AJAX helper intelligence is now available in a view and layout page.
Now it’s time to add script reference in a view or layout page.
NOTE
if your application is making too many AJAX requests throughout the project it is better to add a reference in a layout page. In the code sample I have added this script reference in _Layout page just below the jquery.min.js script reference.
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
We have seen that both HTML helper and AJAX helper method generate the anchor tag, now the question is where to use the @HTML.ActionLink and @AJAX.ActionLink.
For that consider the following situation.
Whenthe user clicks on the link and you want to redirect user to another different page in that situation you have to use @HTML.ActionLink.
When the user clicks on the link and you don’t want to redirect to different page, but you want them to stay on the same page and display some information or details without Post Back, at that time it’s better to use @AJAX.ActionLink.
@AJAX.ActionLink has 12 different overloads; here I have explained the most important one that is mostly used.
In the sample code I have used ASP.NET MVC5 applications using the Entity Framework 6 and Visual Studio 2015. For more information about how to work with Entity Framework Getting Started with Entity Framework 6 using MVC 5
@AJAX.ActionLink Example
1. Create AJAX action link,
/Views/Home/Index.cshtml
@Ajax.ActionLink("View All Student Info", "AllStudent", "Home", new AjaxOptions
{
UpdateTargetId = "divAllStudent",
OnBegin = "fnOnBegin",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET",
LoadingElementId = "imgloader",
OnSuccess= "fnSuccess",
Confirm="Do you want to get all student info ?????"
}, new { @class = "btn btn-default" })
/Controllers/HomeController.cs
2. Create action method.that will call on action click event.
[HttpGet]
public PartialViewResult AllStudent()
{
using (TempEntities db = new TempEntities())
{
var objAllStudent = db.StudentInfoes.ToList();
return PartialView("AllStudent", objAllStudent);
}
}
Views/Home/AllStudent.cshtml
3. creating a partial view that will return all student info.
@model IEnumerable<StudentInfo>
<table class="table">
<tr>
<th>@Html.DisplayNameFor(model => model.FirstName)</th>
<th>@Html.DisplayNameFor(model => model.LastName)</th>
<th> @Html.DisplayNameFor(model => model.MobileNo)</th>
<th>@Html.DisplayNameFor(model => model.Address)</th>
</tr>
@foreach (var item in Model) {
<tr>
<td> @Html.DisplayFor(modelItem => item.FirstName)</td>
<td>@Html.DisplayFor(modelItem => item.LastName)</td>
<td>@Html.DisplayFor(modelItem => item.MobileNo)</td>
<td> @Html.DisplayFor(modelItem => item.Address)</td>
</tr>
}
</table>
In @Ajax.ActionLink,First parameter is the link text that will be displayed on the User Interface. Second parameter is an action method name that you want to call asynchronously. Third parameter is name of controller. Now the most important parameter is AjaxOptions. The following different options are available in AjaxOptions class.

Hassan AijazPosted Aug 6, 2020, 4:57 AM
All Ok but what happen OnFailure how we get the actual error behind if it fail
Vo Khanh ThuyPosted Jul 27, 2017, 10:38 PM
Thanks you. this article help me have a clearly knowledge about ajax helper
Ibrahim SiddiquePosted Mar 5, 2017, 1:08 AM
Nice article brother it was very helpful for me.
Parth MehtaPosted Jan 28, 2017, 2:07 AM
Nice .. help full. good work keep it up
Delpin Susai RajPosted Aug 28, 2016, 9:32 AM
Nice one
Rahul Kumar SaxenaPosted Apr 4, 2016, 7:47 AM
Good show
Mayank SharmaPosted Apr 1, 2016, 8:10 AM
Very good share
Vignesh ManiPosted Mar 30, 2016, 5:54 AM
Nice one
MannanPosted Mar 30, 2016, 1:44 AM
Mr.Sohail. most of the Ajax controls are paid,comparativly heavy than the ajaxhelper where as microsoft Unostrusive.ajax.js is open source and it is easy to use.
sagar nathePosted Mar 30, 2016, 1:07 AM
Very nice share..
hitesh kalalPosted Mar 30, 2016, 12:44 AM
Very Nice Article and it is very help full ..
Nikhil RajputPosted Mar 30, 2016, 12:44 AM
Nice One......................
Jaipal ReddyPosted Mar 30, 2016, 12:21 AM
Nice Share. .
Gakenh01Posted Mar 29, 2016, 2:39 PM
Good example. Thank you. Bookmarked!
Saillesh PawarPosted Mar 29, 2016, 2:18 PM
Nice share
Kashif SohailPosted Mar 29, 2016, 1:58 PM
when we have ajax controls, then why we need this?
Ankur MistryPosted Mar 29, 2016, 11:20 AM
welldone , good work
Mohammed IbrahimPosted Mar 29, 2016, 11:07 AM
nice