I would like to set the value based on a Tempdata but it is not showing . My TempData value stored is '2012-09-28'. I tested both below but it is not displaying in the datepicker:
Model.cs
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
[DataType(DataType.Date)]
public Nullable<DateTime> bookDate{ get; set; }
MyPage.cshtml
@Html.EditorFor(m => m.myModel.bookDate, new { @Value = "2012-09-28", htmlAttributes = new { @class = "form-control"} })
@Html.EditorFor(m => m.myModel.bookDate, new { @Value = TempData["myDate"], htmlAttributes = new { @class = "form-control"} })
When you use
@Html.EditorFor,the value of myModel.bookDate will cover@Value = "2012-09-28".You can try to do like this: