[英]How to get this Display Template working for Dates for DisplayFor in MVC3. Trivial I think
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. 我需要显示此日期时间,例如“ 01/01/2013 20.13”,我希望通过“显示模板”进行显示。 I have a partial view in Shared/DisplayTemplates called "ShortDateTime.cshtml" with the following code: 我在Shared / DisplayTemplates中有一个名为“ ShortDateTime.cshtml”的局部视图,其中包含以下代码:
@model System.DateTime?
@Model.HasValue ? Model.Value.ToString("dd/MM/yyyy") : string.Empty
The value can be null by the way. 顺便说一下,该值可以为null。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.