I'm using the DataType.Date attribute on my model and an EditorFor in my view. This is working fine in Internet Explorer 8 and Internet Explorer 9, but in Google Chrome it is showing a date picker and instead of displaying the value it just displays "Month/Day/Year" in faded gray text.
Why won't Google Chrome display the value?
Model:
[DataType(DataType.Date)]
public Nullable<System.DateTime> EstPurchaseDate { get; set; }
View:
<td class="fieldLabel">Est. Pur. Date</td>
<td class="field">@Html.EditorFor(m=>m.EstPurchaseDate)</td>
Best Answer
When you decorate a model property with
[DataType(DataType.Date)]
the default template in ASP.NET MVC 4 generates an input field oftype="date"
:Browsers that support HTML5 such Google Chrome render this input field with a date picker.
In order to correctly display the date, the value must be formatted as
2012-09-28
. Quote from the specification:You could enforce this format using the
DisplayFormat
attribute: