Nopcommerce Developer's Guide (vi): Data validation

Source: Internet
Author: User
Tags nopcommerce

Original link: http://docs.nopcommerce.com/display/nc/Data+Validation

Translation By:yersans, if there is inappropriate, please correct me, bo main mailbox: [email protected]. Reprint please indicate the source.

Data validation refers to the processing of data in a program's operations to ensure that it is clean, correct, and useful. Most. NET developers use data annotation validation. But Nopcommerce is using Fluent Validation. It's a small one. NET validation libraries, using the fluent interface and lambda expressions to generate validation rules for business objects. To add a validation to the Nopcommerce model, you need to complete the following two steps:

1. Create a Abstractvalidator derived class that contains all the validation logic. As shown below:

   public class addressvalidator:abstractvalidator<addressmodel>    {public        addressvalidator ( Ilocalizationservice localizationservice)        {            rulefor (x = x.firstname)                . Notempty ()                . Withmessage (Localizationservice.getresource ("Address.Fields.FirstName.Required"));        }    }

2. Mark your model class with a validation attribute. As shown below:

    [Validator (typeof (Addressvalidator))]    public class Addressmodel:basenopentitymodel    {

When the view model is passed to the controller, ASP. NET will be properly validated.

Nopcommerce Developer's Guide (vi): Data validation

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.