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。支持的日期/时间类型是:
我真的不想创建自定义编辑器模板,因为标准MVC编辑器模板工作正常,除了type="datetime"
属性值是非标准的。
如何覆盖DateTime对象的EditorFor
方法的默认行为,以便创建<input type="date">
元素而不创建自己的编辑模板?
答案 0 :(得分:3)
使用DataType属性
注释模型字段public class Model1
{
[DataType(DataType.Date)]
public DateTime BegineDate { get; set; }
}