1

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!

1 Answer 1

1

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)
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.