How to send result back in JSON format in MVC

Total Post:9

Points:45

Mvc 
 1163  View(s)
Ratings:
Rate this:
  1. How to send result back in JSON format in MVC

    In MVC, we have the JsonResult class by which we can return back data in JSON format. Below is a simple sample code which returns back a Customer object in JSON format using JsonResult.

    public JsonResult getCustomer()
    {
       Customer obj = new Customer();
       obj.CustomerCode = "1001";
       obj.CustomerName = "Shiv";
       return Json(obj,JsonRequestBehavior.AllowGet);
    }

      Modified On Mar-29-2018 01:53:16 AM

Answer