Closed louieo closed 7 years ago
I'm assuming you're using WebAPI2 rather than the WebApi that's part of AspNetCore?
That call to FluentValidationModelValidatorProvider.Configure();
definitely doesn't look right - the WebApi integration doesn't have a method that takes 0 parameters. Do you definitely have the FluentValidation.WebApi package installed rather than FluentValidation.Mvc5? The Configure method in the WebApi integration requires an HttpConfiguration
to be passed as the first parameter:
FluentValidationModelValidatorProvider.Configure(configuration);
I had the WebAPI package installed but was using using FluentValidation.Mvc instead of using FluentValidation.WebApi; in my WebApiConfig class.
All working now. Thanks for the fast reply!
Hi, I have the following DTO in my WebAPI project decorated with the attribute :
Validator implementation:
Controller decorated as such:
Custom ActionFilterAttribute:
...and config is set up like this:
public static class WebApiConfig { public static void Register(HttpConfiguration configuration) { configuration.Filters.Add(new ValidateModelFilter()); FluentValidationModelValidatorProvider.Configure(); }
A breakpoint in ValidateModelFilter.OnActionExecuting works, yet breakpoint is never hit on first line of CustomerAddressDTOValidator and ModelState.IsValid is always true in the Controller action when I expect a validation issue.
Can you please help me with what might be wrong here?