There's a way to set the default resource to the data annotations validations?
I don't wanna make something like this:
[Required(ErrorMessage="Name required.", ErrorMessageResourceType=typeof(CustomDataAnnotationsResources)]
public string Name { get; set; }
I would like something like this:
Global.asax
DataAnnotations.DefaultResources = typeof(CustomDataAnnotationsResources);
then
[Required]
public string Name { get; set; }
someone gimme a light!
thanks in advance
EDIT
My real problem was with EF Code First CTP4. CTP5 fix it. Thanks for everyone.
Best Answer
You could try doing this:
Add this class somewhere in your project:
and in your global.asax, add the following:
It will look for a property with the same name as the validator type for the error message. You can change that via the ResourceNameFunc property.
EDIT: AFAIK this works from MVC2 onwards, as DataAnnotationsModelValidatorProvider was introduced in MVC2.