Think I am doing something silly here.
I have :
@Html.DisplayFor(modelItem => item.DateCreated,"ShortDateTime")
I need to display this datetime like "01/01/2013 20.13", and I wish to do it via Display Templates. I have a partial view in Shared/DisplayTemplates called "ShortDateTime.cshtml" with the following code:
@model System.DateTime?
@Model.HasValue ? Model.Value.ToString("dd/MM/yyyy") : string.Empty
The value can be null by the way.
I believe my Template is incorrect, and I need corrections on this please.
Many thanks in advance.
Try:
@Html.DisplayFor(model => model.DateCreated, "ShortDateTime")
and in your template:
@model System.DateTime?
@(Model.HasValue ? Html.Raw(Model.Value.ToString("dd/MM/yyyy")) : null)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.