on this project we do not use the default dataannotation attributes from the System.ComponentModel.DataAnnotations namespace, but custom attributes are built.
So we do place a [required] attribute on a property, but it’s a custom built one.
For server side validation we managed to override the validation with a custom validation provider, but we are stuck with tthe client side validation.
As i read in the docs, i see that when you use the default [required] attribute, these kind of attributes are rendered on the html elements:
data-val-lengthmax="10" data-val-length-min="3" data-val-required="The ClientName field is required."
I presume that is done by the framework, which reads the normal required attribute, and then renders the html attributes.
Can we make the framework render these attributes for us too?
Yes, there are 2 possibilities:
IClientValidatableinterface where you would implement the client validation rules.DataAnnotationsModelValidator<TAttribute>where TAttribute will be your custom validation attribute and where you would implement your custom client side validation rules (that’s the approach used by Microsoft to implement client side validation for the Required attribute and that’s why if you write a custom validator attribute which derives from it you don’t get client side validation). Then you need to register your custom model validator with the custom attribute usingDataAnnotationsModelValidatorProvider.RegisterAdaptercall.