Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I want to completely disable model validation for WebAPI controllers. I tried a few ways to do it for MVC, but seems WebAPI doesn't get that methods.

In my case:

  1. custom formatter creates and populates object
  2. default validation happens
  3. Object passed to controller
  4. My code start working

I'm trying to completely remove step 2.

share|improve this question
    
can u clarify further. do you have data annotations setup on your poco classes? do you have code in http verb methods that look like if(ModelState.IsValid)? if so you should remove that. Maybe I'm not fully understanding you. – origin1tech May 22 '13 at 18:42
    
I`m trying to completely remove default validation, not just ignore it. – Oleh Nechytailo May 23 '13 at 12:47
    
Not enough upvotes on this question ;-) This validation, we didn't know or care about, was automatically running every method in every object we sent, killing performance by about 3000% (confirmed via profiling). Very relieved to turn it off. – PandaWood Feb 9 '15 at 5:21
up vote 7 down vote accepted

Try this:

config.Services.Clear(typeof(ModelValidatorProvider));

It should completely disable validation both for URI parameters and for body parameters.

share|improve this answer
1  
It throws exception "ModelValidatorProvider is not supported", so I removed System.Web.Http.Validation.IBodyModelValidator and it works! Thanks. – Oleh Nechytailo May 23 '13 at 12:45
    
On thing to note, this needs to be called before EnsureInitialized() or the route bindings will be setup with the default validator. – michael.aird Jan 14 '14 at 15:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.