NoWar
NoWar

Reputation: 37633

DataType(DataType.Date) format (MVC)

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.

Thank you!

Upvotes: 5

Views: 28043

Answers (1)

Eric J.
Eric J.

Reputation: 150108

You can use the DisplayFormatAttribute

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

Upvotes: 16

Related Questions