srkirkland / DataAnnotationsExtensions

Validation extensions for DataAnnotations, including optional MVC client validation implementations
https://dataannotationsextensions.apphb.com/
BSD 3-Clause "New" or "Revised" License
308 stars 86 forks source link

DateTime server side validation #47

Closed Robelind closed 12 years ago

Robelind commented 12 years ago

Using the following model property:

[Required(ErrorMessage = "Required")] [Date(ErrorMessage = "Wrong format")] [DataType(DataType.Date)] public DateTime Date { get; set; }

With client side validation the messages "Required" and "Wrong format" are displayed as expected. With only server side validation an empty input gives the expected "Required" validation message, but wrong format gives the default "The value 'aaa' is not valid for Date.". I'd expect it to be "Wrong format".

srkirkland commented 12 years ago

Try changing model year to a string and the validation error message should kick in. I'm betting the problem here is that when you use DateTime ASPNET MVC's default type checking will override any extensions and you won't get the custom error message.