Unable to set membernames from custom validation attribute in MVC2

后端 未结 4 2218
甜味超标
甜味超标 2020-12-11 17:04

I have created a custom validation attribute by subclassing ValidationAttribute. The attribute is applied to my viewmodel at the class level as it needs to validate more tha

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 17:16

    You need to set the ErrorMessage property, so for example:

     public class DOBValidAttribute : ValidationAttribute
    {
        private static string _errorMessage = "Date of birth is a required field.";
    
        public DOBValidAttribute() : base(_errorMessage)
        {
    
        }
    //etc......overriding IsValid....
    

提交回复
热议问题