blindworld
blindworld

Reputation: 121

How do I pass datetimes between a controller and a view in MVC?

Our model has public DateTime date { get; set; }. In our view, our dates are being stored in the JSON date format. We're then trying to save updates to the date

var someObject = {};
someObject.date = JSONDate;
$.post("Controller/SaveAction", someObject, callback);

and our controller has public JsonResult SaveAction(ModelType model) { ... } but this code breaks because it is unable to convert the JSON date to a c# DateTime object.

How can I convert the JSON date to something that the post will controller will be able to correctly read into a C# DateTime object?

Upvotes: 3

Views: 182

Answers (1)

Robert Harvey
Robert Harvey

Reputation: 180787

Your best bet is probably using the JSON.NET library, where things like this have already been defined and (more or less) standardized.

http://json.codeplex.com/

Upvotes: 2

Related Questions