Reputation: 11731
I have a web application made in asp.net mvc 4
in Global.asax, i added added IsoDateTimeConverter
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(
new IsoDateTimeConverter { DateTimeFormat = "dd-MM-yyyy hh:mm" });
}
I have an ActionResult
public ActionResult GetDate()
{
DateTime dateTime = DateTime.Now;
return Json(dateTime, JsonRequestBehavior.AllowGet);
}
However, this actionResult returns this:
"\/Date(1365060823129)\/"
What i am missing?
Upvotes: 5
Views: 5334
Reputation: 24125
Well I believe you got a little bit confused by all the "not precise" naming which lot of people have been using lately. The JsonFormatter
(and formatters in general) is used by ASP.NET Web API.
You are not using ASP.NET Web API, you are using ASP.NET MVC 4 (those are completely separated technologies).
In ASP.NET MVC 4 the serialization logic is still done inside the JsonResult
with JavaScriptSerializer
, formatters are not applied here.
If you want to use Json.NET (and its IsoDateTimeConverter
) with ASP.NET MVC 4 you still need to create your own ActionResult
as described here.
Upvotes: 6