This question has been asked before, but the answers do not solve my problem. The problem is that I always get the following error in the datetime field.
The Create Time field must be a date.
My attempt
It is modal here where I set the date format
[Display(Name = "Created Time")] [DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)] public Nullable<System.DateTime> CreatedTime { get; set; }
View code
<div class="form-group"> @Html.LabelFor(model => model.CreatedTime, "Timesheet Date") <div class='input-group date' id='Datetimepicker1'> @Html.TextBoxFor(model => model.CreatedTime, new { @class = "form-control" }) <span class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div> @Html.ValidationMessageFor(model => model.CreatedTime, "", new { @class = "text-danger" }) </div>
In js
$('#CreatedTime').removeAttr("data-val-date"); $('#Datetimepicker1').datetimepicker({ format: 'DD/MM/YYYY' });
Also tried changing in jquery.validate.js funcation date: function (value, element) as shown below, but could not solve the problem.
if ($.browser.webkit) { //ES - Chrome does not use the locale when new Date objects instantiated: var d = new Date(); return this.optional(element) || !/Invalid|NaN/.test(new Date(d.toLocaleDateString(value))); } else { return this.optional(element) || !/Invalid|NaN/.test(new Date(value)); }
Visited Links
The field must have a date - date check Picker does not run in Chrome - mvc
Field date must be date in mvc in chrome
And many more links and sites, but unable to solve the problem
javascript jquery date google-chrome asp.net-mvc-5
user2963609
source share