我想根据Tempdata设置值,但它没有显示。我存储的TempData值为"2012-09-28"。我测试了下面两个,但它没有显示在日期选择器中:
型号.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"} })
当您使用@Html.EditorFor
时,myModel.bookDate的值将覆盖@Value = "2012-09-28"
。您可以尝试这样做:
<input id="myModel.bookDate" name="myModel.bookDate" value=@TempData["myDate"] class="form-control" type="date"/>