I have this controller action :
[HttpGet]
public ActionResult CreateForm(Models.ReminderModel model)
{
if (model.FkUserId == null && model.FkRoleId == null) {
model.FkUserId = UserSession.Current.UserId;
model.ReminderDate = DateTime.UtcNow;
}
return View(model);
}
The action behaves normally if no URL param is specified, but when I specify some data, everything gets set BUT ReminderDate
. For example, the request is performed with
model[0][name]:FkUserId
model[0][value]:2
....
model[2][name]:ReminderDate
model[2][value]:2013-03-09T10:33:04.934Z
...
Note : the params are serialized view jQuery and always worked fine until now. It's the first time we try to pass a DateTime
back to a controller action.
In the action controller, model.FKUserId
will correctly be set, however ReminderDate
will be set to "0001-01-01T00:00:00.000Z"
.
What am I missing?
** Update **
As it turned out, C# will not work with ISO formatted date time strings. It prefers UTC ones. Something like 2013-03-05T16:23:00.000Z
needs to be sent as u20130305212358000
(EST). A binding would've been sufficient as well, but I think this is the best solution.