Assign format of DateTime with data annotations?

前端 未结 10 1541
梦如初夏
梦如初夏 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:22

    Use this, but it's a complete solution:

    [DataType(DataType.Date)]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
    

提交回复
热议问题