1,490 questions
0
votes
2
answers
135
views
Custom error message for failed model binding with FluentValidation
I’m building an ASP.NET Core MVC application with a view model that contains a nullable enum, decimal and other int properties.
Example:
public class UserViewModel
{
public decimal? Amount { get; ...
0
votes
2
answers
86
views
FluentValidation with ASP.NET Core MVC: DTOs without data annotations still trigger default "is required" messages
I have an ASP.NET Core 9.0 MVC project where I use DTOs for input binding and FluentValidation 12.x for validation.
Entities exist separately and contain data annotations attributes like [Required] ...
0
votes
1
answer
36
views
Fluent Validation error not firing due to list for comparison being empty
This a continuation of this question: ASP.NET MVC Create View - Where to place ValidationMessage (Fluent Validation) for a variable
ASP.NET MVC
Firstly, all the validation rules are firing except the ...
0
votes
1
answer
68
views
ASP.NET MVC Create View - Where to place ValidationMessage (Fluent Validation) for a variable
I have this validator class:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using DocumentFormat.OpenXml.Linq;
using ...
2
votes
1
answer
67
views
Fluent Validation working in Create but not Edit
Both Create and Edit views use the same validations controller. Create works correctly, showing error messages, and saves upon correcting any validation issues, taking you to the Index view.
For the ...
4
votes
1
answer
176
views
How to make FluentValidation rules optional (skip validation for null/empty strings)?
Validation framework:
using FluentValidation;
namespace ASValidation.Validators.Common
{
public static class CommonValidators
{
// Validates address: max 200 chars, allowed ...
0
votes
1
answer
69
views
FluentValidation and IRuleBuilder.SetValidator() with dynamic rule sets
Given these models:
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
public class FooOfType
{
public string TypeName ...
0
votes
1
answer
73
views
FluentValidation unit test with context.RootContextData
I have a unit test that I pass RootContextData, i.e.
var context = new ValidationContext<Person>(person);
context.RootContextData["MyCustomData"] = "Test";
var validator = ...
-1
votes
1
answer
41
views
FluentValidation and IRuleBuilder.SetValidator() with parameters
FluentValidator's .SetValidator() method has an overload that takes params but I can't find any documentation about the use of those params.
IRuleBuilderOptions<T, TProperty> SetValidator(...
2
votes
2
answers
81
views
Validate all properties are NOT null if one of the properties is not null
I have a record like this:
public record UpdateRequest
{
public int? Prop1 { get; init; }
public int? Prop2 { get; init; }
public int? Prop3 { get; init; }
}
Using Fluent Validation, I ...
2
votes
1
answer
64
views
Validation failing when it should pass: .Empty()/.When()
I am trying to understand why my validation test is failing, when I expect it to pass.
Here is the code:
using FluentValidation;
namespace FluentValidationIssue
{
public class Model
{
...
0
votes
0
answers
36
views
Fluentvalidation .WithName() and .WithMessage() before or after .When()
Currently i got this code:
public static IRuleBuilderOptions<T, TProperty> NotEmptyWithName<T, TProperty>(
this IRuleBuilder<T, TProperty> ruleBuilder,
string fieldName,
...
0
votes
0
answers
25
views
FluentValidator RuleForEach evaluation on a collection should not run next rule for a element if it fails current rule
Suppose I have a class Entity that has a list of strings as controls. I want to make sure each element of the list: 1- Has exactly one "/" in it. 2- It actually just separates two valid ...
1
vote
2
answers
143
views
Validating database entity in ASP.NET Core Web API using fluent validation
I'm using fluent validation in my ASP.NET Core Web API. While this works perfectly for scenarios like empty or greater than scenarios, I want to validate database keys / ids.
For example, while adding ...
0
votes
1
answer
120
views
Fluent Validation - Multiple messages for one rule
Is there a way to return multiple messages on one rule?
public class EmployeeValidator : AbstractValidator<Employee>
{
public EmployeeValidator ()
{
RuleFor(p => p.StartDate)....
1
vote
1
answer
113
views
Use Fluent Validation to compare values in an array
I have an array of objects I am receiving in an HTTP Post body. Looks something like this:
{
load: {
stops: [
{
Name: "Stop 1",
AppointmentDateTime:...
-1
votes
1
answer
96
views
Why I'm not getting 100% code coverage even after completing all the cases?
This is my query class:
public class GetRolesQuery : GenericDetailsPaginatedQueryBase
{
public string[] OrganizationIds { get; set; } = [];
public DateTime? FromDate { get; set; }
public ...
1
vote
1
answer
156
views
C# Unit testing FluentValidation and mocking nested validator (.SetValidator)
I'm working on a .NET 4.8 project and using FluentValidation v9.5.4. I can't update the version for reasons beyond my control.
Using the example classes from FluentValidation docs:
public class ...
0
votes
0
answers
32
views
How to display FluentValidation validation on Razor page for Mediatr Command field that is not displayed on page
I am working on a project that has Razor pages, Mediatr, and FluentValidation in the tech stack. For one page, the Mediatr Command object contains a Dictionary similar to the following:
public record ...
0
votes
0
answers
53
views
Will derived validators using FluentValidation fail if we include a rule set that doesn't exist?
Suppose I have the following domain models in a C# .NET 6 EF Core project:
public abstract class BaseItem
{
// Base class implementation...
}
public class FooItem : BaseItem
{
// Derived ...
0
votes
1
answer
47
views
Turning off validation on a nested blazor custom control
This is for a .NET 8 blazor webapp.
I have a grid that has an Editor Template as follows:
<EditorTemplate>
@{
CurrentlyEditedItemSupplier = (context as ItemSupplier)!;
<HiSS.Body....
0
votes
1
answer
43
views
'IValidationContext' does not contain a definition for 'CloneForChildValidator'
Im getting this error after i upgrade my fluent Validation package from 8.6.3 to 9.2.2
Could someone please help ?
public class PolymorphicValidator<TBaseClass> : NoopPropertyValidator
...
1
vote
1
answer
149
views
How to implement role-based validation using FluentValidation
We have a number of web api services that currently use FluentValidation and SharpGrip.FluentValidation.AutoValidation for automatic asynchronous validation. It works really well.
At present the ...
0
votes
0
answers
38
views
WithMessage method does not work after SetValidator to override the error message
Consider I have a validator like this:
public class validatorTest : AbstractValidator<model>
public validatorTest() => _ = this.RuleFor(model => model.Name).NotNull().WithMessage("...
1
vote
1
answer
69
views
FluentEditForm says that there is no data, despite data entered being there
My code, below, is a fluenteditform form. After I submit, it says that the fields still need to be filled out even though I filled them out. What is wrong with my code?
@page "/movieform"
@...
0
votes
1
answer
515
views
Is it a bad practice to use Fluent Validation with GET request that has body request?
I am attempting to use Fluent Validator in my project. Most of the tutorials that I come so far is using with a post request where you have a json body as a object and that object will be validated by ...
-1
votes
1
answer
62
views
How To register FluentValidation from multiple assemblies
How can i add fluentvalidation which have validation in multiple assemblies.
I have validators also in a shared class Library:
public class TestModelValidator : AbstractValidator<TestModel>
...
0
votes
1
answer
69
views
Error with Fluent validation using Generic
I am trying to create a generic class for fluent validation. Refer the following code.
public abstract class GenericValidator<T> : AbstractValidator<T>
{
/// <summary>
/// ...
-1
votes
1
answer
142
views
Validate a generic collection using SetValidator in Fluentvalidation
I am trying to validate a generic type:
public class Request<T> where T : class
{
public int Test { get; set; }
public List<T> Records { get; set; } = [];
}
How do I set the ...
1
vote
1
answer
135
views
Multiple FluentValidator Rules for one Class
I have a single class
public class Foo
{
public string Name { get; set;}
public string Email { get; set;}
public int Id { get; set;}
}
And my objective is to have 2 differents rules in a ...
1
vote
1
answer
79
views
Identifying a specific failed validator for a property with multiple validators
In Fluent Validation, I have multiple validators on a single property, like so:
RuleFor(c => c.MinSize)
.GreaterThanOrEqualTo(limits.MinLimit)
.LessThan(c => c.PreferredSize ?? limits....
0
votes
1
answer
163
views
IPipelineBehavior ValidationBehavior doesn't get triggered when registered in MediatR
I'm replacing all exception with Result<T> by the LangExt library. The problem is ValidationBehavior doesn't even get triggered. It used to trigger when the method signature used to be public ...
0
votes
1
answer
169
views
In-line validation with dynamic components in Blazor/Mudblazor
I am using MudBlazor form components to create a form. The form has some static components and some dynamic components. I am having trouble getting the dynamic components to validate.
Form
<...
1
vote
1
answer
349
views
Fluent Validation execute rule depending on multiple other rules
Let's say we have a few validators:
RuleFor(request => request.User)
.NotEmpty()
.Must(Exist);
RuleFor(request => request.Room)
.NotEmpty()
.Must(Exist);
RuleFor(request => ...
1
vote
0
answers
560
views
Fastendpoints Validator with injected constructor
I'm trying Fastendpoints for organize endpoints in a .net8 web-api project. I have configured validators as follows
Issue is when the app starts in local environment it shows the following fail ...
1
vote
1
answer
148
views
Is there a way to reuse tests in xUnit?
Let's say that I have a type called Widget.
Widget
public class Widget
{
public int? Id { get; set; }
public string? Name { get; set; }
public List<Item>? Items { get; set; }
}
I ...
0
votes
0
answers
91
views
Deprecation of Transform and TransformForEach methods How to use New way with Front End in Blazor
I was looking at using Transform but it looks like it will be removed soon and a new way with computed properties is to be used.
https://github.com/FluentValidation/FluentValidation/issues/2072
My ...
1
vote
1
answer
107
views
Fluent validation check to pass only one query parameter from given 2 query parameter
I have get web api where I need to write down fluent validation which we check user can only pass one query parameter.
I have 2 parameters name as action and promo.where parameters types are boolean
...
1
vote
0
answers
72
views
Problem after autocomplete in FluentValidation
If browser autocomplete two field in my register form (email + password) then validator always return true, but form has two others field (confirm password + terms). I can't find solution for this, ...
1
vote
1
answer
866
views
How to Validate Immediately After Leaving Control with Fluent Validation + Blazor Server
I am using Blazor Server, Fluent Validation and Blazored.FluentValidation. I have not really used Fluent Validation for front end for a very long time but I remember when I was using Jquery Validate + ...
0
votes
1
answer
137
views
FluentValidation TestHelper: Handling OverridePropertyName in Unit Tests
Question:
I'm using FluentValidation in my .NET application and have a custom validation method for phone numbers that uses .OverridePropertyName("phone_number"). The validation method works ...
1
vote
0
answers
734
views
Cannot pass null model to Validate. (Parameter 'instanceToValidate')
I need to validate PinCode send from UI, this value need to check with database if not null. I have this code to validate using Fluent Validations:
public class PinCodeValidator : AbstractValidator<...
0
votes
0
answers
57
views
Validating only changed properties of a class file with FluentValidation
I have an endpoint that updates (PUTs) an entity. However, the entire class file is not required, only the property the requestor wants to change.
How do I get FluentValidation to just validate the ...
2
votes
1
answer
138
views
ASP.NET Core - How to resolve error in Fluent Validation
I have this code in an ASP.NET Core 8 Web API using Fluent Validation:
public class CreateBranchBulkUploadCommand : IRequest<Response<string>>
{
public IFormFile File { get; set; }
}
...
0
votes
1
answer
93
views
How can I create a RuleSet with a .NET FluentValidation InlineValidator? [2024]
This is an up-to-date version of this question, as the solution no longer applies.
I've implemented fluent validation and am now building tests. The developers of FluentValidations strongly suggest ...
0
votes
0
answers
53
views
Is it possible to get a reference of the input control that got an error in the summary?
I need to have a validation summary with a anchor to the input control that have the error so the user can click on it and get into the input without having to "find" it
the input have ...
1
vote
1
answer
74
views
ASP.NET Core - How to resolve no accessible extension method 'MessageFormatter' Error in Fluent Validation
In ASP.NET Core-8 Web API, I am implementing Custom Messages with Fluent Validation
DTO:
public class CreateAccountRequestDto
{
public int PreferredClassCode { get; set; }
public DateTime ...
2
votes
1
answer
1k
views
FluentValidation uses array index instead of dictionary key when validating dictionary items (Items[0].Name instead of Items["foo"].Name)
Preamble: This is a follow-up to an older question about .NET 4 and ASP.NET 5 with FluentValidation 8.5. While this could be considered a duplicate, enough has changed with FluentValidation over the ...
1
vote
0
answers
205
views
How to validate that byte is greater or equal than specific value using FluentValidation?
I'm using the package FastEndpoints ( which ships FluentValidation ). Given a class defining the request object
using System.Text.Json.Serialization;
namespace MyProj;
public sealed class Request
{
...
1
vote
0
answers
88
views
How to trigger fluent validation on change of a dependent property value change?
I have a Boolean property 'AnyLetter' depending on five other Boolean properties. The fluent validation is working when I hit on submit but I would like it trigger like 'Location' property, when value ...