I have in my Model this field
[DataType(DataType.DateTime)]
[Required(ErrorMessage = \"Expire is required\")]
public DateTime Expire
{
get;
@inherits System.Web.Mvc.WebViewPage<System.DateTime>
should be
@inherits System.Web.Mvc.WebViewPage<System.DateTime?>
This is the code of my editor template: The point is to avoid null values:
@model DateTime?
<script src="../../../Scripts/jquery-1.4.4.js" type="text/javascript"></script>
<script src="../../../Scripts/jquery-ui.js" type="text/javascript"></script>
@Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : String.Empty), 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>
Just put ? in your System.DateTime
example :
@model System.DateTime?
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue,
new
{
data_datepicker = true
})
if you ommit the question mark you will ge an error
Try one of the following:
return View(new MyObject())
@inherits System.Web.Mvc.WebViewPage<System.DateTime>
to @inherits System.Web.Mvc.WebViewPage<System.DateTime?>