Reputation: 3930
I have a strongly typed partial view with a date in it, like this -
@model Models.MyModel
MyDate: @Html.DisplayFor(m => m.MyDate)
With JQuery, I am posting back in the following manner -
var urlPost = Url.Action("MyArea", "MyController", "MySaveAction");
$.post(urlPost, form, function (returnHtml) {};
My controller looks like this -
[HttpPost]
public ActionResult MySaveAction(MyModel m)
{
// My code
}
The other properies in the model are posting fine, but "MyDate" is not. "MyDate's" value is displayed as "1/18/2010 12:00:00 AM", but is posting back as "1/1/0001 12:00:00". Can someone tell me why?
Thanks very much for any help!
Upvotes: 1
Views: 57
Reputation: 1038810
The DisplayFor helper only displays. If you want the value to be sent to the server when you submit the form, you need to have a corresponding input field. Probably hidden in your case:
@model Models.MyModel
MyDate: @Html.DisplayFor(m => m.MyDate)
@Html.HiddenFor(m => m.MyDate)
Upvotes: 1