Reputation: 27384
I have an Angular front end that sends back JSON to an MVC back end. All dates are converted in JS, using moment()
to ISO format before being sent i.e. StartDate: 2015-02-17T15:06:12.180Z
For some reason MVC does not treat these as being in UTC and will convert them to local time. One thing I do use though is MVC's ability to automatically parse JSON into POCOs. My method signature is as follows:
[HttpPost]
public ActionResult AddSchedule(Schedule schedule)
How can I make MVC treat dates properly?
Upvotes: 2
Views: 591
Reputation: 1816
That isn't the behaviour I would expect. Usually when I pass JSON containing dates to c#, they are not changed to local times. Is there code in your Schedule parameter-less constructor that could be affecting the dates?
If not you might have to use the C# ToUniversalTime() function on your dates after they are passed into your controller.
Upvotes: 2