The scalability of the Asp.net MVC framework means that it is feasible to implement the custom verification logic. There are two core methods:
1. encapsulate the verification logic in custom data annotations.
2. encapsulate the verification logic in the model object.
Encapsulating the verification logic in custom data annotations allows you to easily reuse the logic in multiple models. This requires you to write code within the feature to correspond to different types of models. Once implemented, new Annotations can be reused in multiple places.
If the verification logic is put into the model object, it means that the verification logic can be easily encoded, but it is not conducive to the reuse of the logic.
I. Custom annotations
All verification annotation features are ultimately derived from the base class: validationattribute, which is an abstract class. The verification logic must also be derived from validationattribute. At least one isvalid method must be reloaded in the Custom annotation to return the validity of the model.
Ii. ivalidatableobject
The self-validating model refers to a model object that knows how to verify itself. A model object can be verified by implementing the ivalidatableobject interface.