Define configuration to disable validation for mvc controllers.
See original GitHub issueI 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:
- Created 7 years ago
- Comments:17 (11 by maintainers)
Top GitHub Comments
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:
Now (after v0.10.3 release), you can disable it in PreInitialize of your module like that:
It’s similar to Web API and ASP.NET Core.