Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 自定义ValidationAttribute未在无效数据视图上触发_C#_Jquery_Validation_Razor_Attributes - Fatal编程技术网

C# 自定义ValidationAttribute未在无效数据视图上触发

C# 自定义ValidationAttribute未在无效数据视图上触发,c#,jquery,validation,razor,attributes,C#,Jquery,Validation,Razor,Attributes,因此,我有以下自定义属性: public class YearOrOlderAttribute : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (value == null || (int)value <= DateTime.Now.Year) {

因此,我有以下自定义属性:

public class YearOrOlderAttribute : ValidationAttribute
{
   protected override ValidationResult IsValid(object value, ValidationContext validationContext) 
   {
      if (value == null || (int)value <= DateTime.Now.Year)
      {
         return true;
      }

      return new ValidationResult($"Year must be less than {DateTime.Now.Year}");
}
在我看来,我有以下几点:

[YearOrOlder(ErrorMessage = "You can't go back to the future!")]
public int? YearInput { get; set; }
@Html.Kendo().TextBoxFor(model => model.YearInput)
我在页面上按这个顺序显示jquery->jquery.validate->jquery.unobtrusivevalidation

自定义属性仅在表单提交后命中,而不是在模糊时命中。如果我做了一个基本的“[Range(12344321)]”属性,那么会触发很好的结果,并显示错误消息。为什么我的自定义属性没有被触发