【发布时间】:2013-07-20 16:47:07
【问题描述】:
我的模型类中有一个 DateTime 类型的属性。如何以特定格式呈现它 - 例如返回 MM/dd/yyyy?
我已经在模型中尝试过这个......
[DisplayName("Activation Date")]
//[DataType(DataType.Date)]
//[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime ActivationDate {get;set;}
我无法删除时间!
我想用 DisplayFormat 做到这一点
为什么这个[DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")]
不工作??
在我看来我有
<div class="editor-label">
@Html.LabelFor(model => model.ActivationDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ActivationDate)
@Html.ValidationMessageFor(model => model.ActivationDate)
</div>
【问题讨论】:
-
您的视图中有什么?
-
我在上面添加视图代码
-
您是否需要格式化此数据以进行验证目的?
-
是的,我也想知道为什么 DisplayFormat 不起作用?
-
您的 EditorTemplates 文件夹中有 DateTime 的 EditorTemplate 吗?
标签: asp.net-mvc