Blazor-Validation is a validation agnostic library for validating forms in Blazor - Microsoft aspdotnet Blazor project.
You can download the latest release / pre-release NuGet packages from the official NuGet pages:
- Add a reference to PeterLeslieMorris.Blazor.Validation
- Inside the
<EditForm>
in your razor files, add<PeterLeslieMorris.Blazor.Validation.Validate/>
- In startup.cs add
using PeterLeslieMorris.Blazor.Validation
and then add the relevant validation in theConfigureServices
method.
services.AddFormValidation(config => config.AddDataAnnotationsValidation());
services.AddFormValidation(config => config.AddFluentValidation();
It is possible to add as many validation providers as you wish
services.AddFormValidation(config =>
config
.AddDataAnnotationsValidation()
.AddFluentValidation()
);
The standard Blazor components <ValidationSummary>
and <ValidationMessage>
will now work with your selected validation options.
More sample projects will be added as the framework develops.
- Data Annotations Sample - Shows how to use DataAnnotations to validate.
- FluentValidation Sample - Shows how to use the [FluentValidation.com] library to validate.