1
我有一个必需的属性与资源使用:ASP.NET MVC 2:数据DataAnnotations验证是惯例
public class ArticleInput : InputBase
{
[Required(ErrorMessageResourceType = typeof(ArticleResources), ErrorMessageResourceName = "Body_Validation_Required")]
public string Body { get; set; }
}
我想指定资源成为惯例,这样的:
public class ArticleInput : InputBase
{
[Required2]
public string Body { get; set; }
}
基本上,Required2
实施基于此数据的值:
ErrorMessageResourceType = typeof(ClassNameWithoutInput + Resources); // ArticleResources
ErrorMessageResourceName = typeof(PropertyName + "_Validation_Required"); // Body_Validation_Required
Is there任何方式来实现这样的事情?也许我需要实施一个新的ValidationAttribute
。
我可以用一个适配器与任何验证属性?只需使用'DataAnnotationsModelValidator'? –
stacker
2010-05-28 21:05:13
@stacker - 现有的属性已经注册了适配器。内部字典的确切类型也是如此,所以我认为您需要为每个属性类型配备一个适配器。 – tvanfosson 2010-05-28 21:25:44