Date Format using Html.DisplayFor() in MVC5

前端 未结 4 1965
旧时难觅i
旧时难觅i 2021-01-05 11:20

Referencing the answer in this post I added /Views/Shared/DisplayTemplates and added a partial view called ShortDateTime.cshtml as shown below:

@model System         


        
4条回答
  •  渐次进展
    2021-01-05 11:54

    I guess you should declare the BirthDate property as nullable in model class

    public DateTime? BirthDate{ get; set; }
    

    and you must have declared as

    public DateTime BirthDate{ get; set; }
    

    this will expect a value every time.

    if you set as nullable it will not expect a value.

提交回复
热议问题