I've got an ASP.NET MVC 5 application. Date fields are prolific. Things are working and behaving propertly, however the W3C Markup Validator complains about the date text fields having an improper type
attribute value.
I'm rendering the input
's for DateTime
or nullable DateTime
properties using the EditorFor
helper:
@Html.EditorFor(model => model.BeginDate)
This is getting translated to:
<input type="datetime">
The "datetime" value of the type
attribute is no longer a standard according to the W3C HTML5 Forms standard. The supported date/time types are:
- date - A date (year, month, day) with no time zone
- time - A time (hour, minute, seconds, fractional seconds) with no time zone
I don't really want to create a custom Editor Template, because the standard MVC editor template works perfectly, except the type="datetime"
attribute value is non-standard.
How can I override the default behavior of the EditorFor
method for DateTime objects so it creates <input type="date">
elements without creating my own Editor Template?