question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CustomizeValidatorAttribute for WebAPI

See original GitHub issue

Hi @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:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
JeremySkinnercommented, Mar 6, 2018

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.

1reaction
JeremySkinnercommented, Mar 6, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating Your Own Validation Attribute In MVC And Web ...
Creating Your Own Validation Attribute In MVC And Web API 2.0 · Required - It ensures that the value must be provided to...
Read more >
Model validation in ASP.NET Core MVC and Razor Pages
For scenarios that the built-in validation attributes don't handle, you can create custom validation attributes. Create a class that inherits ...
Read more >
c# - Custom validation at controller level in web api
You need to implement the ValidationAttribute class and then you can write your own logic and use as data annotation on your models....
Read more >
How To Do Custom Validation Using ValidationAttribute of ...
ValidationAttribute class is included in the DataAnnotations namespace. It helps you to validate the model data received from the user. It gives you...
Read more >
Advanced Model Validation For .NET Core Web APIs
First option is to create custom validation attribute. ValidationAttribute is an abstract class and it is used as base class for all the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found