I have this model with the following data annotation because I want to handle the date in this format : dd.MM.yyyy
[DataType(DataType.Date)]
[DateRange(ErrorMessageResourceName = "DateBetween", ErrorMessageResourceType = typeof(WizardStrings))]
[DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
public DateTime? BirthDate1 { get; set; }
In the view :
@Html.EditorFor(model => model.BirthDate1 )
@Html.ValidationMessageFor(model => model.BirthDate1)
MVC still render this date with the following format : dd/MM/yyyy it seems like it doesn't take my data annotation into account.
See the rendered HTML :
<input class="text-box single-line valid" data-val="true" data-val-required="La date de naissance est requise!" id="BirthDate1" name="BirthDate1" type="text" value="**9/9/1999 12:00:00 AM**">
Before DataFormatString try adding ApplyFormatInEditMode = true
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd.MM.yyyy}")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With