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.

Quick validation of complex types in Blazor

Saturday, 16 July 2022
By TonyTony  


Quick validation of complex types in Blazor

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

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.

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.

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


 In your EditForm, replace the DataAnnotationsValidator tag with ObjectGraphAnnotationsValidator.

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.

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



Are you expecting to see a validation message for you complex type fields? here's the solution.
Checkout this guide on how to get pass the hurdle on making the index db works on your Blazor WASM project.
Blazor framework piqued my interest when I first heard it. By the time I've checked it out during the pandemic, .NET 5 just got released. Most of the opinion I've got were that Blazor technology is still not production ready, well for me, it doesn't matter as this framework/technology is developer's dream framework. I will not list those features but what piqued my interests are working with the webAssembly and PWA features. To start off with the Blazor project, you can launch your Visual Studio 2019 and select the Blazor App project from the project template list.
Leave a reply

I hope this information helps, if you have any further questions please don't hesitate to contact us.

Your e-mail address will not be published.

arrow_upward