How do you perform custom validation in a Blazor EditForm that goes beyond Data Annotations?
Last updated
Create a
ValidationMessageStoreagainst theEditContext, clear it before re-validating, and add errors withstore.Add(fieldIdentifier, message).Run your logic in
OnValidationRequested(full model on submit) andOnFieldChanged(per field as the user edits).Alternatives: implement
IValidatableObjectfor cross-field checks, or useFluentValidationwith a validator component for complex rules.
- https://learn.microsoft.com/en-us/aspnet/core/blazor/forms/validation?view=aspnetcore-10.0
- https://www.bytefish.de/blog/custom_form_validation_blazor.html
- https://learn.microsoft.com/en-us/aspnet/core/blazor/forms/validation-advanced?view=aspnetcore-10.0
- https://www.telerik.com/blogs/blazor-basics-advanced-blazor-form-validation
- https://www.binaryintellect.net/articles/608df8cd-c68d-4a88-a6ca-1c1c544615a1.aspx
- https://www.luisllamas.es/en/blazor-custom-validation-complex-rules/