Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

FluentValidation

> 编程语言
Open source

A library for using FluentValidation with Blazor

651 stars0 likes1 views
WebsiteGitHub

About

A library for using FluentValidation with Blazor

FluentValidation

A library for using FluentValidation with Blazor

Important Notice from Contributor

Unfortunately, I'm no longer able to maintain this project. The NuGet key has expired, and I don't have a way to renew it. Rather than trying to patch things up, I've decided to channel my efforts into a complete rewrite.

Introducing Blazilla — a fresh take on FluentValidation for Blazor. This new project was built from the ground up to address many of the lingering issues in the original implementation. If you're looking for a modern, actively maintained solution, I encourage you to check it out.

GitHub – Blazilla

Thanks for your support!
~ Paul

Installing

You can install from Nuget using the following command:

Install-Package Blazored.FluentValidation

Or via the Visual Studio package manger.

Basic Usage

Start by add the following using statement to your root _Imports.razor.

razor
@using Blazored.FluentValidation

You can then use it as follows within a EditForm component.

razor

    
    

    

        Name: 
        
    

    

        Age: 
        
    

    

        Email Address: 
        
    

    Save

@code {
    private Person _person = new();

    private void SubmitValidForm()
        => Console.WriteLine("Form Submitted Successfully!");
}

Finding Validators

By default, the component will check for validators registered with DI first. If it can't find, any it will then try scanning the applications assemblies to find validators using reflection.

You can control this behaviour using the DisableAssemblyScanning parameter. If you only wish the component to get validators from DI, set the value to true and assembly scanning will be skipped.

xml

You can find examples of different configurations in the sample projects. The Blazor Server project is configured to load validators from DI only. The Blazor WebAssembly project is setup to load validators using reflection.

Note: When scanning assemblies the component will swallow any exceptions thrown by that process. This is to stop exceptions thrown by scanning third party dependencies crashing your app.

The validator must be publicly accessible and inherit directly from AbstractValidator.

Async Validation

If you're using async validation, you can use the ValidateAsync method on the FluentValidationValidator.

razor

    
    

    

        Name: 
        
    

    

        Age: 
        
    

    

        Email Address: 
        
    

    Save

@code {
    private Person _person = new();
    private FluentValidationValidator? _fluentValidationValidator;

    private async void SubmitFormAsync()
    {
        if (await _fluentValidationValidator!.ValidateAsync())
        {
            Console.WriteLine("Form Submitted Successfully!");
        }
    }
}

RuleSets

RuleSets allow validation rules to be grouped and executed together while ignoring other rules. RulesSets are supported in two ways.

The first is setting RuleSets via the Options parameter on the FluentValidationValidator component.

razor
 options.IncludeRuleSets("Names"))" />

The second is when manually validating the model using the Validate or ValidateAsync methods.

razor

@code {
    private FluentValidationValidator? _fluentValidationValidator;

    private void PartialValidate()
        => _fluentValidationValidator?.Validate(options => options.IncludeRuleSets("Names"));
}

Access to full ValidationFailure

If you need details about the specifics of a validation result (e.g. its Severity), you can access the result of the last validation by calling the GetFailuresFromLastValidation method on the FluentValidationValidator component.

razor

@code {
    private FluentValidationValidator? _fluentValidationValidator;

    private string GetValidationClass() 
    {
        var lastResult = _fluentValidationValidator?.GetFailuresFromLastValidation();
        if (lastResult is null || !lastResult.Any())
        {
            return "valid";
        }
        if (lastResult.Any(failure => failure.Severity == Severity.Error))
        {
            return "invalid";
        }
        return "warning";
    }
}

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#blazorblazoredcsharpfluentvalidation

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言