我的模型中有这个字段
[DataType(DataType.DateTime)]
[Required(ErrorMessage = "Expire is required")]
public DateTime Expire
{
get;
set;
}
在我看来
@Html.EditorFor(model => model.Expire))
@Html.ValidationMessageFor(model => model.Expire)
我创建日期时间编辑器模板
@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>
当我尝试创建新项目时,我收到此错误消息
模型项传递到
字典为空,但是这个
字典需要一个非空模型
类型为“System.DateTime”的项目
I try
Model.HasValue ? Model.Value.ToString("MM/dd/yyyy") : DateTime.Today.ToShortDateString()
但我没有在模型值检查
尝试以下方法之一:
- 如果操作是为了创建新对象,则传递新实例作为模型,例如
return View(new MyObject())
- Change
@inherits System.Web.Mvc.WebViewPage<System.DateTime>
to @inherits System.Web.Mvc.WebViewPage<System.DateTime?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)