Quad A

Quick validation of complex types in Blazor

Saturday, 16 July 2022
Welcome to my another Blazor series short topic, Validating Complex Type in a quick way in Blazor or if you having a problem in validating a reference field in your model. The problem with the current Blazor’s DataAnnotationValidator doesn’t include validation for complex type fields which I’ve scoured the internet for solution and here we go.


Blazor Quick validation of reference field or complex types


First, we’re going to add DataAnnotation.Validation nuget package in both your UI and Model projects. As you can see, this package is currently experimental and its currently on release candidate.


Decorate your model with [ValidateComplexType] to mark the field as a complex type.


In your EditForm, replace the DataAnnotationsValidator tag with ObjectGraphAnnotationsValidator.


And, that’s it, the following fields from the Address object is now being validated here.



You may also like

View this article on its original page