Assign format of DateTime with data annotations?

前端 未结 10 1545
梦如初夏
梦如初夏 2020-11-27 14:03

I have this attribute in my view model:

[DataType(DataType.DateTime)]
public DateTime? StartDate { get; set; }

If I want to display the dat

10条回答
  •  爱一瞬间的悲伤
    2020-11-27 14:24

    In mvc 4 you can easily do it like following using TextBoxFor..

    @Html.TextBoxFor(m => m.StartDate, "{0:MM/dd/yyyy}", new { @class = "form-control default-date-picker" })
    

    So, you don't need to use any data annotation in model or view model class

提交回复
热议问题