I'm a beginner of asp.net jquery and html5 and I'm developing an asp.net mvc 4 site where I have a form with two Date fields. I don't want to insert a date manually, so I tried to use this solution to implement a simple datepicker:
<fieldset>
<legend>RangeDateViewModel</legend>
<div class="editor-label">
Start Date
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.StartDate, new{ @class = "date" })
@Html.ValidationMessageFor(model => model.StartDate)
</div>
<div class="editor-label">
End Date
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.EndDate, new{ @class = "date" })
@Html.ValidationMessageFor(model => model.EndDate)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/jqueryui")
@Styles.Render("~/Content/themes/base/css")
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".date").datepicker();
});
</script>
}
the code works good, but if I select a date from 13th until 30/31 th of the month i have always the same warning: "The field StartDate must be a date." and "The field EndDate must be a date."
EDIT: I add my ViewModel as asked:
public class RangeDateViewModel
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}