I know that my question has been discussed on several occasions, but I don't seem to able to find a clear answer to my problem. What am I doing incorrectly?!
I am using Bootstrap datepicker and keep receiving the message "The Field {name} must be a date." I'm sure that the issue is to do with formatting, because when I enter 01/01/2016 it is fine but 13/01/2016 shows the validation error.
I have read that this is to do with the datepicker format, or globalization settings but I think that I've covered most of these; others have referred to problems with partial views but I don't think that this is my issue as the date is not in a partial view. What have I done wrong?
Date Picker code:
<script type="text/javascript">
$('.datepicker').datepicker({ format: 'dd/mm/yyyy', startView: 'years' }); //Initialise any date pickers
</script>
View:
<div class="form-group">
@Html.LabelFor(m => m.BirthDate, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.BirthDate, new { @class = "form-control datepicker", @id = "DateOfBirth" })
@Html.ValidationMessageFor(m => m.BirthDate, "", new { @class = "text-danger" })
</div>
</div>
Model
[Required(ErrorMessage = "Date of Birth is required")]
[Display(Name = "Birth Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime BirthDate { get; set; }
Web Config
<system.web>
<globalization uiCulture="en-GB" culture="en-GB" />
</system.web>