Custom verification Logic

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.