JSON date format problem in ASP.NET MVC

Posted by Sheonarayan under Error and Solution on 12/13/2015 | Points: 10 | Views : 3313 | Status : [Administrator] | Replies : 0


While returning a JSON string from controller action method to the view, the date and time field gets converted into numeric digit like this.


Easiest Solution

The easiest solution of this problem is to use NewtonSoft to serialize to json string instead of using inbuilt ASP.NET MVC

// return Json(model, JsonRequestBehavior.AllowGet); // do not use this
return Json(Newtonsoft.Json.JsonConvert.SerializeObject(model), JsonRequestBehavior.AllowGet); // use this

Using NewtonSoft JsonConvert would change the date to readable format like below


Will write a complete article soon on this on how to change even the date format and how to change the json property names to camelCase.


Sheo Narayan


(No response found.)

Login to post response