expressappframework-402980-getting-started-in-depth-tutorial-blazor-enable-additional-modules-implement-property-value-validation.md
This lesson explains how to set validation rules for entity classes and their properties. XAF applies these rules when a user executes a specific operation (for example, saves an edited object).
The Validation System offers a number of predefined rule types and contexts. A rule specifies a data validity condition. A context defines the moment when the application checks the rule.
To use XAF Validation functionality, you need the DevExpress.ExpressApp.Validation.Blazor and DevExpress.ExpressApp.Validation.Win NuGet packages. When you created the solution and selected the Validation module in the project wizard, the wizard added these packages to platform-specific projects.
Tip
To add this functionality to an existing application, you need to install the NuGet packages and register the modules. For additional information, refer to the following section: Validation System Elements.
The instructions below explain how to do the following:
DemoTask.Status is NotStarted).Position.Title property must not be empty.Open the Model.DesignedDiffs.xafml file in the Model Editor. Navigate to the Validation | Rules node. Right-click the Rules node and select Add… | RuleCriteria.
Set values of the following properties for the node:
Navigate to the ActionDesign | Actions | DemoTask.MarkCompleted node and set the ValidationContexts property to MarkCompleted.
Change the caption of the MarkCompleted Action to Mark Completed.
Run the application and go to one of the unfinished tasks. Click the Mark Completed button. The following Validation Error dialog appears:
Apply the RuleRequiredField attribute to the Title property in the Position class. Specify the context that triggers the rule (for example, DefaultContexts.Save) as the attribute’s parameter:
Run the application and go to the Position List View.
See Also