Using a jQuery DatePicker function in my C# MVC program but its giving me an error either saying "Invalid Date" or my default date of today "17/05/2017" is invalid.
Here's my jQuery as well as my Labels/Editors in my Create.cshtml:
<div class="editor-label">
@Html.LabelFor(model => model.DateOfReading)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DateOfReading)
@Html.ValidationMessageFor(model => model.DateOfReading)
</div>
<script>
if (datefield.type!="date"){ //if browser doesn't support input type="date", initialize date picker widget:
jQuery(function ($) { //on document.ready
$('#DateOfReading').datepicker({ dateFormat: 'dd/mm/yy', maxDate: 0, defaultDate: 0 }).val(new Date().toLocaleDateString());
})
}
</script>
Here's my entity:
[Required(ErrorMessage = "You must input a date")]
[Display(Name = "Date of Meter Reading")]
[DataType(DataType.Date)]
public DateTime DateOfReading { get; set; }