4

In my MVC4 project I have a controller action as follows:

public ActionResult GetJson()
{
    var serialized = JsonConvert.SerializeObject(DateTime.Now);
    return Json(DateTime.Now, JsonRequestBehavior.AllowGet);
}

The response to the browser is in the old ASP.NET format:

"/Date(1358987787691)/"

However, I know that MVC4 uses json.net by default, and that json.net uses ISO8601 format for dates.

In the code above, the serialized variable contains (what I want):

"\"2013-01-24T13:39:12.7182079+13:00\""

Why is return Json(DateTime.Now) not (seemingly) using json.net?

I have also tried putting the following line in my global.asx:

var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.UseDataContractJsonSerializer = false;

but to no avail.

2
  • Seems I've misunderstood the documentation - json.net is the default json formatter for web API only. Commented Jan 24, 2013 at 0:52
  • 1
    The answer seems to be here: james.newtonking.com/archive/2008/10/16/… Commented Jan 24, 2013 at 0:53

1 Answer 1

1

You could make some changes in controller factory and create your controller, which is inherited from standard controller, but used custom json formatter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.