I have a Model that is using DataAnnotations. Something like
public class Appointment {
[Required(ErrorMessage="Please enter your name")]
public string Name { get; set; }
[Required(ErrorMessage="Please enter your appointment date?")]
[DataType(DataType.Date, ErrorMessage="Appointment date is not a date")]
public DateTime AppointmentDate { get; set; }
}
The "Required" attributes respect the value in ErrorMessage; that is, if I don't enter a value, I am getting my "please enter" message. However, if I enter a string in the DateTime field, I am getting a standard system error message "The value 'blah' is not valid for AppointmentDate".
I debugged through ASP.NET MVC code, and it seems that in the case of FormatException it doesn't pick the right display name from propertyMetadata. Either that, or I am missing something blatantly obvious :/
Did anybody run into this problem? Is it me, or is it just beta (I am using ASP.NET MVC 2 Beta)?