Time Input Field in ASP.NET MVC

前端 未结 4 1737
萌比男神i
萌比男神i 2020-12-21 08:29

I\'m having trouble trying to write a form with time field using ASP.NET MVC 4.

Model:

class Abcde {
    [DataType(DataType.Time)]
    public DateTim         


        
4条回答
  •  萌比男神i
    2020-12-21 09:12

    [Required]
    [DataType(DataType.Time)]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:H:mm}")]
    public DateTime Time { get; set; }`
    

    Try this, you can format in the DataFormatString the way you want it to work for you, im using it in a project now and it's working for me.

提交回复
热议问题