ASP.NET MVC 2: Data DataAnnotations validation be convention
- by stacker
I have a required attribute that used with resources:
public class ArticleInput : InputBase
{
[Required(ErrorMessageResourceType = typeof(ArticleResources), ErrorMessageResourceName = "Body_Validation_Required")]
public string Body { get; set; }
}
I want to specify the resources be convention, like this:
public class ArticleInput : InputBase
{
[Required2]
public string Body { get; set; }
}
Basically, Required2 implements the values based on this data:
ErrorMessageResourceType = typeof(ClassNameWithoutInput + Resources); // ArticleResources
ErrorMessageResourceName = typeof(PropertyName + "_Validation_Required"); // Body_Validation_Required
Is there any way to achieve something like this? maybe I need to implement a new ValidationAttribute.