I'm using MVC2 and have included the Jquery DateTime picker. For some reason it is not using the default format settings when the pages loads.
The model is passing in a Date and I have set the format to 'dd/mm/yyyy' as I do not want the time to be displayed. The html.editorfor that the datepicker is attached to, shows in the standard 'mm/dd/yyyy hh:mm:ss' format, consequently the validation kicks in with "invalid Date" if the model value if say '15th October 2010', because the standard format complains that there is no "15th" month.
Code from the DatePicker is...
<%= Html.TextBox("", (Model.HasValue ? Model.Value.Date.ToString("dd/mm/yyyy") :
DateTime.Today.ToString("dd/mm/yyyy") ), new { @class = "date" }) %>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("#datepicker").datepicker(
{
dateFormat: 'dd/mm/yy',
defaultDate: new Date(),
minDate: new Date()
});
});
</script>
Code calling Datepicker...
<div>
<%=Html.LabelFor(Model => Model.StartDate)%>
<%=Html.EditorFor(Model => Model.StartDate, new { @class = "date" }) %>
<%=Html.ValidationMessageFor(Model => Model.StartDate, "*")%>
</div>
Any ideas?