Background
Today, working with modern web applications is one of the most challenging tasks in terms of implementing user-friendly faster response times and consuming fewer resources. This is due to the client or user's high expectations. To solve these problems, there are lots of technologies on the market, but again, it's a challenge for the developer or architect to choose suitable technology and implement it properly.
One of the problems in today's web applications is that they are full of page postbacks, so we will learn about Ajax.beginForm, which is the extension method of the Ajax helper class. By using it, we can post the request to the server without the whole page postback. So let's learn about it from scratch.
What Is Ajax?BeginForm
Ajax.BeginForm is the extension method of the ASP.NET MVC Ajax helper class, which is used to submit form data to the server without whole page postback.
To work Ajax. To begin functionality properly, we need to add the reference of jQuery.unobtrusive-ajax library; there are many ways to add the reference of jQuery library into our project. To learn how to use and install jQuery. unobtrusive-ajax please refer to my following article.
The Ajax.BeginForm takes the following parameters
- actionName
- controllerName
- route values
- ajaxOptions
- HTML attributes
actionName
This parameter is used to define the action name for which the action will be executed.
controllerName
This is the parameter used to define the controller name.
route values
This parameter is used to pass the object which contains the route parameters.
ajaxOptions
This parameter is used to pass the properties for Ajax requests which makes the request to the server asynchronously. ajaxOptions has the following properties.
- Url: This property is used to get and set the URL.
- HttpMethod: This property is used to define the form submit method such as POST, GET, PUT, Delete, etc.
- Confirm: This property is used to display the confirmation box before sending a request to the server.
- UpdateTargetId: This property is used to specify the DOM element id for which part to be updated; such as, if we specify the DIV tag id then only that particular DIV portion will get updated.
- OnSuccess: This property is used to define the JavaScript file that will fire after the successful Ajax request.
- OnFailure: This property is used to define the JavaScript file that will fire after the failed Ajax request.
- OnComplete: This property is used to define the JavaScript file which will fire after the complete Ajax request.
- OnBegin: This property is used to define the JavaScript file that will fire after completing the Ajax request.
- InsertionMode: This property is used to specify how the response will be inserted into the DOM element. It has InsertAfter, InsertBefore, and Replace modes.
- AllowCache: This is the boolean property that decides whether to allow cache or not.
- LoadingElementId: This property is used to display the loading symbol for long-running requests.
- LoadingElementDuration: This property is used to define the duration in milliseconds for the loading symbol.
HTML attributes
This parameter is used to define the HTML attributes such as CSS class, id, etc for HTML elements.
Syntax
@using (Ajax.BeginForm("EmployeeMaster", "Home", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divEmp" }))
Note. To work Ajax. To beginForm functionality properly we need to add the reference of jQuery. unobtrusive-ajax library, there are many ways to add the reference of jQuery library into our project. The following are some methods.
- Using the NuGet package manager, you can install a library and reference into the project.
- Right-click on the created MVC project and find the Nuget Package manager option,

- Now the following window will appear and search for the jQuery unobtrusive Ajax as below.

Choose the appropriate version and click on the Install button. It will install the jQuery UI library to your project and the library script file will get added to the script folder of the created project which you can add as a reference to the project,
- Use the CDN library provided by Microsoft, jQuery, Google, or any other that requires an active internet connection.
- Download the library using NuGet and reference it in the project.
The library will look as follows after adding it to the script folder.

To work Ajax.BeginForm functionality properly don't forget to add the reference of the following jQuery library as below.
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
From the above explanation, we have learned about the Ajax.BeginForm.
Summary
I hope this article was useful for all readers. If you have a suggestion then please contact me.
Read more MVC articles,
- Post Data To Controller Without Page Refresh In ASP.NET MVC
- Paging Sorting Searching In ASP.NET MVC 5
- Disable jQuery UI Calendar Past And Future Date In ASP.NET MVC
- Manage Controller Specific Session In ASP.NET MVC 5
Read more articles on ASP.NET MVC.

Danny CampoverdePosted Aug 31, 2020, 10:26 AM
Every time I use an AJAX form, everything works correctly, but if a user later wants to log in through Azure SSO, he does not leave it and loops. You would think these AJAX forms are causing something in the App Pool. Because then I have to wait an indefinite time so that any user can log in or restart the App Pool
Daniel GillettPosted Jun 12, 2020, 5:56 AM
Hello, I'm using InsertionMode.Replace. The form works and updates on my homepage, showing the form result message. But when I use the form on another page the result message from my partial form does not work.
Dinesh GabhanePosted Nov 12, 2019, 5:57 AM
Nice Article. Thanks
pardeep kumarPosted Oct 17, 2019, 12:57 AM
OnBegin statement is wrong please check it.
Dennis TaylorPosted Apr 1, 2019, 12:37 PM
Just another useless article here on C-#Corner. Thanks for showing is how to use the "@using" statement and how to use the "script" tag. The only useful thing was the link.
Bhavesh PatelPosted May 28, 2018, 5:45 AM
Not getting file name while upload in controler ... eg. HttpPostedFileBase
Sourav Kumar SinghPosted Feb 7, 2018, 4:45 AM
Great Article. But I think OnBegin will be invoked just before starting the AJax Call.
Manav PandyaPosted Sep 14, 2016, 10:15 AM
Vithal Wadje Thanks sir !!!
Vithal WadjePosted Sep 14, 2016, 8:24 AM
Find already downloaded references and after that add into your any project using Add reference by right clicking on your project solution explorer .
Manav PandyaPosted Sep 14, 2016, 6:34 AM
Sir how to include and use any references(Nuget packages) offline ??
Vithal WadjePosted Feb 28, 2016, 11:40 PM
Thanks
Rajeev PunhaniPosted Feb 26, 2016, 6:04 AM
Nice Share.
Vithal WadjePosted Feb 11, 2016, 10:26 AM
Thanks
Amit Kumar SinghPosted Feb 11, 2016, 8:23 AM
Nice one Sir
Vithal WadjePosted Feb 9, 2016, 10:39 AM
thanks
Upendra Pratap ShahiPosted Feb 9, 2016, 4:43 AM
Thanks for sharing sir...great article..
Vithal WadjePosted Feb 7, 2016, 9:18 AM
Thanks Kumaresh sir
Vithal WadjePosted Feb 7, 2016, 9:17 AM
Thanks Pankaj sir
Vithal WadjePosted Feb 7, 2016, 9:17 AM
Thanks Shubham sir
Vithal WadjePosted Feb 7, 2016, 9:17 AM
Thanks jaipal sir
Vithal WadjePosted Feb 7, 2016, 9:17 AM
Thanks Santhakumar sir
Kumaresh RajalingamPosted Feb 7, 2016, 7:23 AM
Nice share sir
Pankaj Kumar ChoudharyPosted Feb 6, 2016, 7:54 PM
Really Helpful Article Sir Thanks For Share.........
Shubham KumarPosted Feb 5, 2016, 11:52 PM
thnx sir
Jaipal ReddyPosted Feb 5, 2016, 11:31 PM
Nice one. .
Santhakumar MunuswamyPosted Feb 5, 2016, 3:31 PM
Thanks for nice article
Vithal WadjePosted Feb 5, 2016, 3:21 PM
Thanks Hemant sir
Vithal WadjePosted Feb 5, 2016, 3:20 PM
Thanks Mohammed sir
Vithal WadjePosted Feb 5, 2016, 3:20 PM
Thanks Jaco sir
Vithal WadjePosted Feb 5, 2016, 3:20 PM
Thanks Ehsan sir
Vithal WadjePosted Feb 5, 2016, 3:20 PM
Thanks Debasis sir
Hemant SrivastavaPosted Feb 5, 2016, 1:45 PM
Thanks for sharing
Mohammed IbrahimPosted Feb 5, 2016, 1:13 PM
nice
Jaco ZwartsPosted Feb 5, 2016, 12:16 PM
Nice Article thanks for sharing
Ehsan SajjadPosted Feb 5, 2016, 11:56 AM
Nice one
Debasis SahaPosted Feb 5, 2016, 9:32 AM
Thanks for share...