Unable to set datetime format in MVC 4 using data annotations

前端 未结 3 1692
暖寄归人
暖寄归人 2020-12-14 09:41

I will try everything but not working this(dd/MM/yyyy) date format, this always gate mm/dd/yyyy

[Display(Name = \"Release D         


        
3条回答
  •  猫巷女王i
    2020-12-14 10:19

    You missed 2 things here:

    DataFormatString="{0:dd/MM/yyyy}"; //It is dd/MM/yyyy instead of dd/mm/yyyy
    

    and you also need:

    ApplyFormatInEditMode=true
    

    Try to use this:

    [Display(Name = "Release Date")]
    [DataType(DataType.Date), DisplayFormat( DataFormatString="{0:dd/MM/yyyy}", ApplyFormatInEditMode=true )]
    public Nullable release_date { get; set; }
    

提交回复
热议问题