Assign format of DateTime with data annotations?

前端 未结 10 1538
梦如初夏
梦如初夏 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条回答
  •  -上瘾入骨i
    2020-11-27 14:35

    That works for me

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

提交回复
热议问题