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.

Define configuration to disable validation for mvc controllers.

See original GitHub issue

I am having an issue since upgrading my application from 0.9.7 to 0.10.0.

Previously my application would enter my controller action even if there were form errors (ModelState) and I could suitably handle this to display the form back to the user with the erroneous fields marked.

Since upgrading the controller action fails to execute because the validation action filter is throwing an exception meaning that I can’t handle errors as I would previously (we are using full MPA post back and not AJAX).

In #1199 the interface IValidate was dropped from IInputDto and in subsequent releases IInputDto has been marked as obsolete.

In the commit against #1199 (https://github.com/aspnetboilerplate/aspnetboilerplate/commit/2db532650d864bd9f0b3114ec15c0997d280130e) it can be seen that the following code was removed from MethodInvocationValidator.cs (line 144):

if (!(validatingObject is IValidate))
{
    return;
}

I think previously, this meant that because my action model inherited from IInputDto that it would also inherit from IValidate and the return statement would mean that an exception wasn’t thrown by the following:

if (ValidationErrors.Any())
{
    throw new AbpValidationException(
        "Method arguments are not valid! See ValidationErrors for details.",
        ValidationErrors
        );
}

I don’t want to disable the validation interceptor globally as I use it at the service level to great effect and I don’t want to have to decorate the majority of my controller actions with [DisableValidation]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
maximejobincommented, Jan 3, 2017

I just wanted to add that if, like me, you found this and wanted to disable the validation only for one controller or one action, you can simply add the attribute over the class or method:

[DisableValidation]
2reactions
hikalkancommented, Jul 27, 2016

Now (after v0.10.3 release), you can disable it in PreInitialize of your module like that:

Configuration.Modules.AbpMvc().IsValidationEnabledForControllers = false;

It’s similar to Web API and ASP.NET Core.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable Model Validation in Asp.Net MVC
I made the " SkipValidationAttribute" approach work, by creating my own impl of ControllerActionInvoker which gets the attribute from the method ...
Read more >
How to Enable and Disable Client-Side Validation in MVC
We can enable and disable the client-side validation by setting the values of ClientValidationEnabled & UnobtrusiveJavaScriptEnabled keys true ...
Read more >
Model validation in ASP.NET Core MVC and Razor Pages
NET Core MVC with controllers and views, the following example shows how to check ModelState.IsValid inside of a controller action:.
Read more >
Spring Validation Example - Spring MVC Form Validator
Validator interface and add set it as validator in the Controller class using @InitBinder annotation. Let's create a simple Spring MVC ...
Read more >
Custom Validation
All ASP.NET MVC and Web API controller actions. See the Disabling Validation section to disable validation if needed. Using data annotations. ASP.NET ...
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