ASP.NET Core 1.1 Hosting: ASP.NET MVC Ajax.BeginForm AjaxOptions OnSuccess, OnFailure

The jQuery Unobtrusive Ajax library complements jQuery Ajax methods by adding support for specifying options for HTML replacement via Ajax calls HTML5 data.hflnet51

Step 1
Create a new MVC Empty Project using Visual Studio. This example shows how to return Ajax Begin Form Ajax Options custom arguments for OnSuccess, OnFailure.

Add new Layout.cshtml into shared folder. Add references of Kendo, CSS, and JavaScript into this Layout.cshtml

Step 2
Add MVC Ajax Nuget Package from Nuget console Manager

 

IMP
Do not forget to add below script references to your cshtml page.

Now, add HomeController in Controller.  There are two action methods, one to take user input, and another to submit data on click event to controller in which I am going to handle this in try catch block.

Step 3
Add View by right clicking on Action Method Index which will accept user input as a date format.

In Ajax.BeginForm there are new AjaxOptions: OnSuccess and OnFailure for success and failure respective responses from action method, and for those we are going to write a javascript alert which will show an appropriate message.

Step 4
Now, run the application. Enter the correct date in input textbox and click on “Submit”.