gpt4 book ai didi

c# - 错误 : The model item passed into the dictionary is null, 但此字典需要类型为 'System.DateTime' 的非空模型项

转载 作者:太空狗 更新时间:2023-10-29 21:09:56 24 4
gpt4 key购买 nike

在我的模型中

[DataType(DataType.Date)]
[Display(Name="Event Date")]
[DisplayFormat(DataFormatString = "{0:d}")]
//[DisplayFormat(ApplyFormatInEditMode=true ,DataFormatString="{0:DD/MM/YYYY}")]
public DateTime EventDate { get; set; }

在我的 View 中 (Create.cshtml)

<div class="editor-label">
@Html.LabelFor(model => model.EventDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.EventDate)
@Html.ValidationMessageFor(model => model.EventDate)
</div>

在 Shared/EditorTemplates/Date.cshtml

@model DateTime
@Html.TextBox("", String.Format("{0:d}", Model.ToShortDateString()),
new { @class = "datefield", type = "date" })

并得到以下错误

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

最佳答案

谢谢 用...解决了它...只需将脚本放入文件中...

@model Nullable<DateTime>



@{
DateTime dt = DateTime.Now;
if (Model != null)
{
dt = (System.DateTime)Model;

}
@Html.TextBox("", String.Format("{0:d}", dt.ToShortDateString()), new { @class = "datefield", type = "date" })
}

<script type='text/javascript'>
$(document).ready(function () {
$(".datefield").datepicker({
// buttonImage: "/content/images/calendar.gif",
// showOn: "both",
// defaultDate: $("#calendar-inline").attr('rel')

showAnim: 'slideDown',
dateFormat: 'dd/mm/yy'

});
});
</script>

关于c# - 错误 : The model item passed into the dictionary is null, 但此字典需要类型为 'System.DateTime' 的非空模型项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10371770/

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