Overview

The DevExpress UI components support Blazor's form validation. You can read about the Blazor forms and validation in the official documentation.

In the demo examples we will use the Starship class that defines validation logic based on data annotations. This class has been taken from the official documentation with only slight modifications.

Note: You should not rely on form validation alone to secure your Blazor-powered app. Form validation is designed to improve usability. A threat actor can bypass validation and send malicious data to the server. To minimize security related threats/risks, you must validate user input using multiple strategies. Refer to the following topic for more information: Validate User Input.

Form Layout

Form Validation State: Press the "Submit" button to validate the form.

Our Form Layout component allows you to easily construct responsive and automatically-aligned edit forms. The standard EditForm component enables data validation. This demo shows how you can use the two components together.

Inside the EditForm, the code adds a Form Layout component with five layout items. Each item contains a DevExpress Data Editor:

The EditForm also contains the DevExpress Button component with the SubmitFormOnClick option set to true. Once you attempt to submit changes, editors become marked with colored outlines. Red indicates invalid values, while green indicates values that were posted successfully. You can also use the ShowValidationIcon global option or an editor's ShowValidationIcon property to specify whether editors should display validation icons.

Below the form, the standard Blazor ValidationSummary component displays the validation summary.

Custom Form

Engine Type:

Form Validation State: Press the "Submit" button to validate the form.

The following example shows a standard EditForm component with a few DevExpress editors in it:

Once you attempt to submit changes, editors are marked with colored outlines. Red indicates invalid values, while green indicates values that were posted successfully. You can also use the ShowValidationIcon global option or an editor's ShowValidationIcon property to specify whether editors should display validation icons.

The code also adds a standard ValidationMessage component for each editor to display error messages.