I have in my Model this field
[DataType(DataType.DateTime)]
[Required(ErrorMessage = "Expire is required")]
public DateTime Expire
{
get;
set;
}
In My View
@Html.EditorFor(model => model.Expire))
@Html.ValidationMessageFor(model => model.Expire)
and I create 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>
when i try to Create new Item I have this error message
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'
I try
Model.HasValue ? Model.Value.ToString("MM/dd/yyyy") : DateTime.Today.ToShortDateString()
But i not have in Model Value check
Try one of the following:
return View(new MyObject())
@inherits System.Web.Mvc.WebViewPage<System.DateTime>
to @inherits System.Web.Mvc.WebViewPage<System.DateTime?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With