我的模型有这样的属性:
[Display(Name = "Date of Service")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] // ISO compliance for jQuery validation
[SqlDateRange] // Enforces min/max SQL DateTime values (also handles nulls caused by invalid dates like "12/01/19900" -- I suppose the issue could be resolved by finding a better way of handling that null case
public DateTime? DateOfService { get; set; }
但是当我在我看来使用它时,
@Html.EditorFor(model => model.Date)
我得到this,它被传递为null。我已经通过属性检查了null
,因为编辑器还允许非常无效的日期,如12/12/21390 - 其中也传递为null
。< / p>
编辑:我正在使用Chrome。
答案 0 :(得分:0)
您所要做的就是在html中输入您想要的格式。我希望它对你有用。
@Html.EditorFor(model => model.Date, "{0:dd/MM/yyyy}")