2

I have problem customizing some default validation messages in ASP.NET MVC4 page. In model class I have following property:

    [DataType(DataType.Date, ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = "DateField")]
    [Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = "RequiredField")]
    public DateTime? CreationDate { get; set; }

When showing error message for Required attribute, everything is OK - my own customized message from ValidationMessages resource file is obtained. However, when validation fails for DataType, the default validation messages is shown.

Is there any explanation for this behaviour? Thanks in advance!

Jan Palas
  • 1,865
  • 1
  • 23
  • 35
  • 1
    what is `DateField` in your `DataType` attribute? – techBeginner Dec 03 '12 at 14:17
  • `DateField` is the name of the resource located in ValidationMessages resx file (could be as well something like "MyCustomDateValidationMessage" - if I renamed the mentioned resource). – Jan Palas Dec 03 '12 at 14:21

1 Answers1

0

As far as I know, ASP.NET validator works through jQuery validator, so interacting through JavaScript might help you.

This answer can help you, I guess: jQuery validation: change default error message

You shouldn't override all of these parameters, of course, only ones you need.

Vizel Leonid
  • 456
  • 7
  • 15