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 a 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 a new item. I have this error message
The model element passed to the dictionary is null, but this dictionary requires a non-empty model element of type 'System.DateTime'
I'm trying to
Model.HasValue ? Model.Value.ToString("MM/dd/yyyy") : DateTime.Today.ToShortDateString()
But I do not have a model value in the check
amchoni
source share