我在我的模型中有这个字段
[DataType(DataType.DateTime)]
[Required(ErrorMessage = "Expire is required")]
public DateTime Expire
{
get;
set;
}
Run Code Online (Sandbox Code Playgroud)
在我看来
@Html.EditorFor(model => model.Expire))
@Html.ValidationMessageFor(model => model.Expire)
Run Code Online (Sandbox Code Playgroud)
我创建了DataTime EditorTemplates
@inherits System.Web.Mvc.WebViewPage<System.DateTime>
@Html.TextBox("", (Model.ToShortDateString()), new { @class = "datePicker" })
<script type='text/javascript'>
$(document).ready(function () {
$(".datePicker").datepicker({
// buttonImage: "/content/images/calendar.gif",
// showOn: "both",
// defaultDate: $("#calendar-inline").attr('rel')
showAnim: 'slideDown',
dateFormat: 'dd/mm/yyyy'
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
当我尝试创建新项目时,我有此错误消息
传递到字典中的模型项为null,但此字典需要"System.DateTime"类型的非null模型项
我试试
Model.HasValue ? Model.Value.ToString("MM/dd/yyyy") : DateTime.Today.ToShortDateString()
Run Code Online (Sandbox Code Playgroud)
但我没有进行模型价值检查
请尝试以下方法之一:
return View(new MyObject())@inherits System.Web.Mvc.WebViewPage<System.DateTime>到@inherits System.Web.Mvc.WebViewPage<System.DateTime?>| 归档时间: |
|
| 查看次数: |
10494 次 |
| 最近记录: |