DataType(DataType.Date)格式(MVC)

时间:2012-11-12 20:32:00

标签: .net asp.net-mvc-3

我们可以以某种方式申请此格式吗?

[Display(Name = "Date of Birthday")]
[DataType(DataType.Date)]
public DateTime DOB { get; set; }

我只希望看到日期,而不是时间。

谢谢!

1 个答案:

答案 0 :(得分:13)

您可以使用 DisplayFormatAttribute

  

指定ASP.NET动态数据如何显示和格式化数据字段。

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayformatattribute.aspx

[DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")]
[Display(Name = "Date of Birthday")]
[DataType(DataType.Date)]
public DateTime DOB { get; set; }