I just ran across this issue today in Chrome. If you create a page with the following
Model:
public class Model {
[DataType(DataType.Date)]
public DateTime LastModified { get; set; }
}
Page:
@Html.EditorFor(x => x.LastModified)
Generates This:
<input type="date" value="01/01/2001" />
However the specs require an RFC 3339 / ISO 8601 Date. The Chrome browser refuses to use the date in this format. Here is the line to the spec.
http://dev.w3.org/html5/markup/datatypes.html#form.data.date
In order to get this to work in MVC4 I have to use the following:
@Html.TextBox(
name: "LastModified"
value: Model.LastModified.ToString("yyyy-MM-dd"),
htmlAttributes: new { type="date" })
Model:
public class Model {
[DataType(DataType.Date)]
public DateTime LastModified { get; set; }
}
Page:
@Html.EditorFor(x => x.LastModified)
Generates This:
<input type="date" value="01/01/2001" />
However the specs require an RFC 3339 / ISO 8601 Date. The Chrome browser refuses to use the date in this format. Here is the line to the spec.
http://dev.w3.org/html5/markup/datatypes.html#form.data.date
In order to get this to work in MVC4 I have to use the following:
@Html.TextBox(
name: "LastModified"
value: Model.LastModified.ToString("yyyy-MM-dd"),
htmlAttributes: new { type="date" })