Convert Date To ToShortDateString In Razor

前端 未结 1 401
太阳男子
太阳男子 2020-12-31 07:14

i have a DateTime Field that must be shown in Edit view

@Html.EditorFor( model => model.StartDate )

how can i use somthing like this ; <

相关标签:
1条回答
  • 2020-12-31 08:01

    Use the [DisplayFormat] attribute on your view model:

    public class MyViewModel
    {
        [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
        public DateTime StartDate { get; set; }
    
        ...
    
    }
    

    and then in your view simply:

    @model MyViewModel
    ...
    @Html.EditorFor(model => model.StartDate)
    
    0 讨论(0)
提交回复
热议问题