I have two separate fields on the page: one for date and one for time.
This is the model:
[Required]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh:mm tt}")]
public DateTime? StartTime { get; set; }
[Required]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime Date { get; set; }
This is the view:
@Html.TextBoxFor(m => m.Date, "{0:MM/dd/yyyy}", new { type = "text" })
@Html.TextBoxFor(m => m.StartTime, "{0:hh:mm tt}", new { type = "text", id = "timeStart" })
The javascript unobtrusive validation works fine with the Date
field however when i enter "11:00 PM" or "11:00 pm" in StartTime
the validation shows
"The field StartTime must be a date"
Server side validation works fine with "0:hh:mm tt"
it's only the javascript that has a problem. For now i just disabled javascript validation but would like eventually to have it on this page
Can this be done for "time" field?