数据类型(DataType.Date)格式(MVC)数据类型、格式、Date、DataType

2023-09-06 16:51:58 作者:好了伤疤忘了疼

我们可以将某种方式的格式呢?

Can we apply somehow the format for this?

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

我想看到的只有日期,而不是​​时间。

I'd like to see only Date and not Time.

感谢您!

推荐答案

您可以使用的 DisplayFormatAttribute 的

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

Specifies how data fields are displayed and formatted by ASP.NET Dynamic Data.

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; }