I created a edit view for a EF Model and have a problem with the datepicker. Whenever i try to edit a `dataset, the edit view don\'t show me the old date values.
Thi
Just like to add an addition to the accepted answer:
<input asp-for="BestellungsDatum" type="date" class="form-control" />
Rather than adding asp-format
to the view, add it to the data Model or ViewModel so you don't have to then add it to every view that uses it:
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime BestellungsDatum { get; set; }
type="date"
generates the browsers HTML-5 datepicker if supported. The specifications require that the value be formatted in ISO format (yyyy-MM-dd
) which is then displayed in accordance with the browsers culture.
Add the asp-format
to format the value, and remove the value
attribute (Tag Helpers correctly generate the value
attribute for correct 2-way model binding and you should never attempt to add it yourself)
<input asp-for="BestellungsDatum" type="date" asp-format="{0:yyyy-MM-dd}" class="form-control" />
Note the HTML-5 datepicker is not supported in IE, and only in recent versions of FireFox. If you want a consistent UI, then consider using a jQuery datepicker instead.