Asp.net custom class data annotation validate on focus lost

I am new to data annotations, so i am trying to get it working. The predefined data annotations like [Required] and [RegularExpression] are working perfectly, however, when i try to add a custom class validation, it is completely ignored. Here's my source code:

namespace Models
{
    public class ModelClass
    {
        [Display(Name = "Test")]
        [CustomClassTest]
        public int? TestIntField { get; set; }
    }
    public class CustomClassTest : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationcontext)
        {
            return new ValidationResult("Work please");
        }
    }
}

ClientValidationEnabled is true, as well as UnobtrusiveJavascriptEnabled. What am i doing wrong here?

EDIT

Apparently, the custom validation class works fine on submitting the form, however, when the focus on the field is lost, the validation message does not appear (unlike other data annotations like [required]). Is there a way to show the validation error on focus lost?

链接地址: http://www.djcxy.com/p/56670.html

上一篇: 具有数据注释验证的复杂类型的Xml架构序列化

下一篇: Asp.net自定义类数据注释验证焦点丢失