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