Using the DatePicker in MVC 3, I have implemented the necessary data model validation provider to have MVC 3 render the data-val-date attribute so I can use unobtrusive validation.
I know this is working a) because I can see the attribute in the page source and b) if I enter text in the datepicker text box and tab, I get the expected "*Invalid date/format." error.
However, if I enter a completely bogus date, say "32/11/2012" and tab, I get no validation error at all. When the form posts to the server, I get server-side validation that the date is invalid. This isn't a huge deal for a straight-up form, at least the bad date is flagged.
The bigger problem is on a grid-popup form that also has a datepicker - the popup exhibits the same behavior, however the bad date is not flagged!!! It is just set to NULL and posted that way to the server. Model object properties in question are below. Screenshot example of missing validation included.
Screenshot 1: Straight-up form with client side validation working when entering text, not working when entering invalid date.
Screenshot 2: Pop-up with client side validation working when entering text
Screenshot 3: Pop-up with client side validation not working completely when entering an invalid date - it flags it as invalid by changing the TB border color to red, but doesn't show error message and doesn't prevent user form Insert!
What am I missing about this?
[Display(Name =
"EOL Date"
)]
[UIHint(
"Date"
)]
[DataType(DataType.Date, ErrorMessage =
"*Invalid date/format."
)]
public
DateTime? EolDate {
get
;
set
; }
[Display(Name =
"Last Order Date"
)]
[UIHint(
"Date"
)]
[DataType(DataType.Date, ErrorMessage =
"*Invalid date/format."
)]
public
DateTime? LastOrderDate {
get
;
set
; }