c# - Custom ValidationAttribute not Firing On Invalid Data Razor Views -
so have following custom attribute:
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 less {datetime.now.year}"); }
on view model have following:
[yearorolder(errormessage = "you can't go future!")] public int? yearinput { get; set; }
on in view have following:
@html.kendo().textboxfor(model => model.yearinput)
i have jquery -> jquery.validate -> jquery.unobtrusivevalidation on page in order.
the custom attribute hit after form submitted, not on blur. if basic '[range(1234, 4321)]' attribute, triggers fine , error message shows. why isn't custom attribute being triggered?
Comments
Post a Comment