Date Format using Html.DisplayFor() in MVC5

前端 未结 4 1958
旧时难觅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:57

    By applying the conditional statement ahead of the Html helper, only non null values get passed.

    @if (item.BirthDate != null) { @Html.DisplayFor(modelItem => item.BirthDate , "ShortDateTime")}
    

提交回复
热议问题