【发布时间】:2011-01-06 16:53:00
【问题描述】:
我的模型中有这个字段
[DataType(DataType.DateTime)]
[Required(ErrorMessage = "Expire is required")]
public DateTime Expire
{
get;
set;
}
在我看来
@Html.EditorFor(model => model.Expire))
@Html.ValidationMessageFor(model => model.Expire)
我创建了 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>
当我尝试创建新项目时出现此错误消息
传入的模型项 字典为空,但这 字典需要一个非空模型 'System.DateTime' 类型的项目
我试试
Model.HasValue ? Model.Value.ToString("MM/dd/yyyy") : DateTime.Today.ToShortDateString()
但我没有在模型值检查中
【问题讨论】:
标签: asp.net-mvc