gpt4 book ai didi

asp.net-mvc - jQuery 日期时间选择器 MVC3

转载 作者:行者123 更新时间:2023-12-01 22:37:35 25 4
gpt4 key购买 nike

我的模型中有这个字段

[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>

当我尝试创建新项目时,我收到此错误消息

The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'

我试试

Model.HasValue ? Model.Value.ToString("MM/dd/yyyy") : DateTime.Today.ToShortDateString()

但我没有模型值检查

最佳答案

尝试以下方法之一:

  • 如果操作是为了创建新对象,则传递一个新实例作为模型,例如return View(new MyObject())
  • 更改@inherits System.Web.Mvc.WebViewPage<System.DateTime>@inherits System.Web.Mvc.WebViewPage<System.DateTime?>

关于asp.net-mvc - jQuery 日期时间选择器 MVC3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4617410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com