@if (Model.RecDateFrom.HasValue)
{
@Html.EditorFor(model => model.RecDateFrom,
new {htmlAttributes =
new {@Value = Model.RecDateFrom.Value.ToString("yyyy-MM-dd"),
@class = "form-control input-sm small-input-fix"}})
}
else
{
@Html.EditorFor(model => model.RecDateFrom,
new {htmlAttributes = new {@class = "form-control input-sm small-input-fix"}})
}
@Html.ValidationMessageFor(model => model.RecDateFrom, "", new {@class = "text-danger"})
You can see above how I have to handle if the datetime is null before setting the value. I have to set the value because MVC uses the incorrect format for a date input, making it so chrome doesn't have the correct default value.
I do not want to use the accepted solution in this question because that changes the format of the display for also.
I've tried using editor templates, but it seems like you have to start from scratch, rather than extending the built in editor template for Date datatypes (this seems like a large flaw of MVC, unless I'm missing something).