相关疑难解决方法(0)

全局本地化验证

我正在使用System.ComponeneModel.DataAnnotations属性,例如Required和StringLength.是否可以全局本地化其错误消息?

我知道我能做到这一点

[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Resources.Validation))]
Run Code Online (Sandbox Code Playgroud)

但到处都这样,我使用必需的属性将是疯狂的.另外我想避免像这样的东西:

public class LocalizedRequiredAttribute : RequiredAttribute {
    public LocalizedRequiredAttribute()
        : base() {
        ErrorMessageResourceName = "Required";
        ErrorMessageResourceType = typeof(Resources.Validation);
    }
}
Run Code Online (Sandbox Code Playgroud)

(但如果没有其他办法,我会满足于此)

validation attributes localization data-annotations asp.net-mvc-3

4
推荐指数
1
解决办法
5276
查看次数