Have a razor form with two date fields displayed as textboxes using the jQuery datepicker plugin for selecting a data range. The start date works fine but the end date fails validation and says "The field End Date must be a date." Below is the Model code and the .cshtml code:
[Display(Name = "Start Date")]
public Nullable<DateTime> startDate { get; set; }
[Display(Name = "End Date")]
public Nullable<DateTime> endDate { get; set; }
<div id="dvDateRange">
@Html.TextBoxFor(e => e.startDate, new { @class = "datepicker", Value = Model.startDate.Value.ToString("dd/MM/yyyy") })
<span> to </span>
@Html.TextBoxFor(e => e.endDate, new { @class = "datepicker", Value = Model.endDate.Value.ToString("dd/MM/yyyy") })
</div>
Both have been set up identically so why would the start date succeed and the end date fail?
Any ideas?
Edit
So is definitely a culture issue and seems to be Chrome that is causing the problem. Have made the following modifications and still get same problem.
Model code:
[Display(Name = "Start Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<DateTime> startDate { get; set; }
[Display(Name = "End Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<DateTime> endDate { get; set; }
.cshtml code:
<div id="dvDateRange">
@Html.EditorFor(e => e.startDate, new { @class = "datepicker", Value = Model.startDate.Value.ToString("dd/MM/yyyy") })
<span> to </span>
@Html.EditorFor(e => e.endDate, new { @class = "datepicker", Value = Model.endDate.Value.ToString("dd/MM/yyyy") })
</div>
Datepicker code:
$("#dvDateRange input").datepicker({
showOn: "button",
buttonImage: "/Images/calendar.gif",
buttonImageOnly: true,
dateFormat: "dd/mm/yy"
});
Anyway of over-riding the culture settings in Chrome?