CustomizeValidatorAttribute for WebAPI
See original GitHub issueHi @JeremySkinner ! I know that CustomizeValidatorAttribute is not supported by WebApi, but I really need it in my project. So I fork your repo to https://github.com/slgal/FluentValidation. I have copied classes from MVC project but I have an issue that WebApi is not call CustomizeValidatorAttribute as a ModelBinder for my models. To be it called I need to use this style:
public IHttpActionResult RulesetTestModel([ModelBinder(typeof(CustomizeValidatorAttribute)]RulesetTestModel model)
instead of
public IHttpActionResult RulesetTestModel([CustomizeValidator(RuleSet = "Names")]RulesetTestModel model)
But how to pass the rules in that case? I would like to ask your advice about how this can be fixed, since I have no idea about it.
Thanks in advance!
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
I spent some more time digging through the WebApi source code today and believe I may have found a way to enable support for CustomizeValidator. I’ll post an update once I’ve done some more testing.
@osnoser1 I just had a quick look and unfortunately this isn’t something that’s going to help, but thanks for the suggestion (although @slgal may find it useful)
Validation needs to take place inside WebApi’s ModelValidatorProvider infrastructure, not inside an action filter. The aim is to get the existing CustomizeValidatorAttribute working with the ModelValidatorProvider api, not to bypass it entirely.