In this article I will explain with an example, how to use Newtonsoft library in ASP.Net Core.
Note: For beginners in ASP.Net MVC Core, please refer my article ASP.Net MVC Core Hello World Tutorial with Sample Program example.

Installing Newtonsoft package using Nuget

In order to install Newtonsoft library using Nuget, please refer my article Installing Newtonsoft library using Nuget.

Configuring the JSON Serializer setting

In order to configure the JSON Serializer settings in ASP.Net Core, please refer my article Configuring Newtonsoft library in ASP.Net Core.


The Model class consist of the following properties.
public class PersonModel
    /// Gets or sets Name.
    public string Name { getset; }
    /// Gets or sets DateTime.
    public string DateTime { getset; }


The Controller consists of following Action methods.

Action method for handling GET operation

Inside this Action method, simply the View is returned.

Action method for handling jQuery AJAX operation

This Action method handles the call made from the jQuery AJAX function from the View.
Note: The following Action method handles AJAX calls and hence the return type is set to JsonResult.
The value of the name parameter is assigned to the Name property of the PersonModel class object along with the current Date and Time.
Finally, the PersonModel class object is returned back as JSON object to the jQuery AJAX function.
public class HomeController : Controller
    public IActionResult Index()
        return View();
    public JsonResult AjaxMethod(string name)
        PersonModel person = new PersonModel
            Name = name,
            DateTime = DateTime.Now.ToString()
        return Json(person);


The View consists of an HTML INPUT TextBox and a Button.
Inside the View, the following jQuery script file is inherited:
1. jquery.min.js
Inside the document ready event handler, the Button has been assigned with a jQuery click event handler which when clicked a jQuery AJAX called is made to the Controller’s action method.
Inside this click event handler, the value of the TextBox is passed as parameter to Controller’s action method.
Finally, the returned response is displayed using JavaScript Alert Message Box.
    Layout = null;
<!DOCTYPE html>
    <meta name="viewport" content="width=device-width" />
    <input type="text" id="txtName" />
    <input type="button" id="btnGet" value="Get Current Time" />
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        $(function () {
            $("#btnGet").click(function () {
                    type: "POST",
                    url: "/Home/AjaxMethod",
                    data: { "name": $("#txtName").val() },
                    success: function (response) {
                        alert("Hello: " + response.Name + ".\nCurrent Date and Time: " + response.DateTime);
                    failure: function (response) {
                    error: function (response) {


Using Newtonsoft library in ASP.Net Core