I am creating an asp.net core web api application. Where I am try to validate my models using fluent validation.
this is my model and validator.
public class Data
{
public string Name { get; set; }
public int Age { get; set; }
}
public class DataValidator : AbstractValidator<Data>
{
public DataValidator()
{
RuleFor(x => x.Name)
.NotEmpty()
.MaximumLength(5);
RuleFor(x => x.Age)
.LessThan(80);
}
}
Everything works fine. Fluent validation returns all the validations together except following case.
When my request contains following JSON, Fluent Validation doesn't get hit. Asp.net core model validation is take place. in that case I am getting single validation error.
{
"name": 123,
"Age" : 100
}
I got following validation message.
The JSON value could not be converted to System.String. Path
- How to override above default message?
- Is there any way to handle above validation in Fluent Validation?
- I want both 'name' and 'age' validation messages together.