I have a search form with inputs for date from and date to and uses a Jquery DatePicker
I have tried every combination of the annotations below
I have a view model with the following
[Display(Name = "Date From")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime DateFrom { get; set; }
[Display(Name = "Date To")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime DateTo { get; set; }
And a View with the following
<div class="form-group">
@Html.LabelFor(m => m.DateFrom)
@Html.TextBoxFor(m => m.DateFrom, "{0:dd/MM/yyyy}", new { @class = "form-control" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.DateTo)
@Html.TextBoxFor(m => m.DateTo, "{0:dd/MM/yyyy}", new {@class = "form-control"})
</div>
And Script with the following (same for #DateTo)
$("#DateFrom").datepicker({
dateFormat: "dd/mm/yy",
showButtonPanel: true,
changeMonth: true,
changeYear: true,
maxDate: 0
});
web.config has the below
<globalization culture="en-GB" uiCulture="en-GB" />
Ive looked at other issues on Stack Overflow but for me the date is still being interpreted at MM/dd/yyyy for both fields.
The correct format appears to come back to the controller correctly.
I get Client Side Validation Error The value '13/08/2015' is not valid for Date From. Anything 01-12/08/2015 will work