I'm having trouble using date of format dd/MMM/YYYY on MVC5 asp.net project. Mostly on Chrome, as it seem to only accept dates of format yyyy/mm/dd.
To normalize behavior across browsers, I'm using a jquery datetimepicker component.
I have tried many things, but Chrome is still saying that the date is not valid. Even after define the input as text instead of date.
Also even if I turn off validation for that particular component (data-val="false"), Chrome still insist on marking the date as invalid.
Model:
public class order
{
[Key]
public int orderID { get; set; }
[Required]
public string comments { get; set; }
[Required]
[DisplayFormat(DataFormatString = "{0:dd/MMM/yyyy}", ApplyFormatInEditMode = false)]
[Display(Name = "Date of Shipping")]
public DateTime date { get; set; }
}
View date input:
<div class="form-group">
@Html.LabelFor(model => model.date, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.date, new { htmlAttributes = new { @class = "form-control datetimepicker" } })
@Html.ValidationMessageFor(model => model.date, "", new { @class = "text-danger" })
</div>
</div>
Imports:
<script src="https://code.jquery.com/jquery-3.2.1.js"/script>
<link rel="stylesheet" type="text/css" href="~/Content/jquery.datetimepicker.min.css" />
<script src="~/Scripts/jquery.datetimepicker.full.min.js"></script>
Javascript:
<script type="text/javascript">
jQuery.datetimepicker.setLocale('es');
jQuery('#date').datetimepicker({
format: 'd/M/Y',
});
</script>