Disable auto-validation
See original GitHub issueFV works just like ASP.NET’s own validation - before an action is executed, it automatically validates the arguments, and populates the ModelState
. So in the action you can check ModelState.IsValid
and everything “just works”.
Is it possible to disable this auto-validation, and only run it on demand?
We use a CQRS pipeline (using MediatR), which performs validation. A typical validator and action:
// the validator
public class CommandValidator : AbstractValidator<Command> { ... }
// the action
public IActionResult Edit(Command command)
{
// note there is no check for ModelState.IsValid
_mediator.Send(command);
return View();
}
So, FV performs auto-validation for that action, and the CQRS pipeline thereafter also performs validation - so the input is validated twice, and the UI shows two validation errors for every invalid property.
Is it possible to configure FV to only validate on demand, and not automatically before every action?
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Disable validation of HTML form elements
If you want to disable client side validation for a form in HTML, add the novalidate attribute to the form element. Ex:
Read more >validate plugin. How to disable auto validation on keypress ...
I wish to be able to disable the automatic validation for one field/element only after submission how can this be done? I have...
Read more >How to disable validation of form's child controls
To achieve this behavior, you can either set the CausesValidation property to false for all child controls or the parent form's AutoValidate ......
Read more >AutoValidate Enum (System.Windows.Forms)
Disable, 0. Implicit validation will not occur. Setting this value will not interfere with explicit calls to Validate() or ValidateChildren().
Read more >autovalidateMode property - Form class - widgets library
Used to enable/disable form fields auto validation and update their error text. If AutovalidateMode.onUserInteraction, this FormField will only ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s nice to have automatic validation for everything in simple configuration entry. But can not ignore some edge cases with an attribute or interface for example?
That’s handled by the FluentValidationClientModelValidatorProvider, which is all set up through the AddFluentValidation() method. If you’re not using the automatic integration, you’ll need to register all that manually (and also create your own ViewOptionsSetup class to plug it into MVC). I’d suggest looking through the code of the FluentValidationMvcExtensions class (https://github.com/JeremySkinner/FluentValidation/blob/master/src/FluentValidation.AspNetCore/FluentValidationMvcExtensions.cs), particularly lines 61-67 and 120-127. That should give you everything you need.