想想我在这里做些傻事。
我有:
@Html.DisplayFor(modelItem => item.DateCreated,"ShortDateTime")
我需要像“01/01/2013 20.13”那样显示这个日期时间,我希望通过显示模板来实现。我在Shared / DisplayTemplates中有一个名为“ShortDateTime.cshtml”的局部视图,其代码如下:
@model System.DateTime?
@Model.HasValue ? Model.Value.ToString("dd/MM/yyyy") : string.Empty
顺便说一下,该值可以为null。
我认为我的模板不正确,我需要对此进行更正。
非常感谢提前。
答案 0 :(得分:1)
尝试:
@Html.DisplayFor(model => model.DateCreated, "ShortDateTime")
并在您的模板中:
@model System.DateTime?
@(Model.HasValue ? Html.Raw(Model.Value.ToString("dd/MM/yyyy")) : null)