Header add

In this article we will discuss How to use AJAX POST in ASP.Net Core.

Here we will explain how to make an AJAX POST call to Controller using jQuery in ASP.Net Core MVC..

Before start this article, please visit our previous article Paging example in ASP.Net Core MVC

Configuring the JSON Serializer setting
Add the NewtonsoftJson package into project

Then inside the ConfigureServices method, you will have to add the following code which will instruct the program to use Newtonsoft library for JSON serialization.

Following is a Model class named CustomerModel with two properties i.e. Name and DateTime


The value of the name parameter is assigned to the Name property of the CustomerModel object along with the Current DateTime and finally the CustomerModel object is returned back as JSON to the jQuery AJAX function.

This Action method handles the call made from the jQuery AJAX function from the View.

The View consists of an HTML TextBox element and a Button. The Button has been assigned a jQuery click event handler and when the Button is clicked a jQuery AJAX called is made to the Controller’s action method.
The URL for the jQuery AJAX call is set to the Controller’s action method i.e. /Home/AjaxMethod. The value of the TextBox is passed as parameter and the returned response is displayed using JavaScript Alert Message Box.


Post a Comment

Previous Post Next Post