I am trying to display a date type input on my create and edit Razor Views... The date picker works fine but when editing I do get the value from the Model but the date pick
If your using this to generate the browsers HTML5 datepicker implementation, the format of the date needs to be yyyy-MM-dd
(ISO format). Using TextBoxFor()
it needs to be
@Html.TextBoxFor(m => m.InitialDate, "{0:yyyy-MM-dd}", new { @class = "form-control", type = "date" })
Alternatively, add the following attributes to the property
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> InitialDate { get; set; }
and in the view use
@Html.EditorFor(m => m.InitialDate)
Note this adds the type="date"
attribute