You need to use the ISO format when using type="date"
[DataType(DataType.Date, ErrorMessage="Date only")]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? YearBought { get; set; }
This will display the date in the browsers culture.
Note there is no need to add @type = "date"
. The EditorFor()
method will add that because of the DataType
attribute. Note also that type="date"
is only supported in Chrome (FireFox and IE will just generate a normal textbox)
If you do want to display the format dd/MM/yyyy
in a standard textbox then you can use
@Html.TextBoxFor(m => m.YearBought, "{0:dd/MM/yyyy}")