In my model
[DataType(DataType.Date)]
[Display(Name="Event Date")]
[DisplayFormat(DataFormatString = "{0:d}")]
//[DisplayFormat(ApplyFormatInEditMode=true ,DataFormatString="{0:DD/MM/YYYY}")]
public DateTime EventDate { get; set; }
in my 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>
in Shared/EditorTemplates/Date.cshtml
@model DateTime
@Html.TextBox("", String.Format("{0:d}", Model.ToShortDateString()),
new { @class = "datefield", type = "date" })
and getting following error
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.
thanks Solved it with.... just putting the script in the file..
@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>
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