[Question] Combining FluentValidation and IValidatableObject Errors
See original GitHub issueIs it possible to run both FluentValidation and IValidatableObject in the same ViewModel? For example if I had the following ViewModel:
public class TestViewModel
{
public Foo Foo { get; set; }
public Bar Bar { get; set; }
}
public class Foo : IValidatableObject
{
public string FooName { get; set; }
public IEnumerable<ValidationResult> Validate(System.ComponentModel.DataAnnotations.ValidationContext validationContext)
{
if (string.IsNullOrEmpty(FooName))
{
yield return new ValidationResult("Required from IValidatableObject", new[] { "FooName" });
}
}
}
[Validator(typeof(BarValidator))]
public class Bar
{
public string BarName { get; set; }
}
public class BarValidator : AbstractValidator<Bar>
{
public BarValidator() {
RuleFor(x => x.BarName).NotNull().WithMessage("Required from FluentValidation");
}
}
Is there a way both Foo and Bar validations can run and return the results when my Controller calls ModelState.IsValid?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Combining FluentValidation and IValidatableObject Errors
Is there a way both Foo and Bar validations can run and return the results when my Controller calls ModelState.IsValid ? c# ·...
Read more >Combining ASP.NET Core validation attributes with Value ...
I want to aggregate a collection of Errors both in your Result class and have the API return them when more than one...
Read more >Using Fluent Validation in ASP.NET Core
With the implementation of Data Annotations in . NET Classes, the problem is that there will be a lot of duplication lines of...
Read more >Solving .NET Validation Challenges with FluentValidation
In this hands-on demonstration, you'll learn how to validate ASP.NET code by implementing an ASP.NET web API with FluentValidation.
Read more >how to implement validation in .net core 6 and entity ...
Fluent validation supports async validation while the built in pipeline always runs synchronous. This allows you to combine all validation ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve just pushed out 7.2-beta1 with initial support for IValidatableObject. Please feel free to give it a try. Note that this only supports top-level objects, but not child properties
It’s something I’d like to enable support for in the future in aspnetcore, but there are a lot of implications for doing this and requires a lot of work, so it’s not something that’ll be added soon I’m afraid.