Skip to content

Commit

Permalink
Merge pull request #18 from SharpGrip/17-net8-fluentautovalidation-an…
Browse files Browse the repository at this point in the history
…d-the-default-modelstateinvalidfilter

fix unvalidated entries when validation is skipped due to annotation configuration
  • Loading branch information
mvdgun authored Oct 19, 2023
2 parents 5decb86 + 8379dde commit 9c95cda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<PropertyGroup>
<PackageVersion>1.3.0</PackageVersion>
<PackageVersion>1.3.1</PackageVersion>
<Company>SharpGrip</Company>
<Authors>SharpGrip</Authors>
<Copyright>SharpGrip</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE
if (autoValidationMvcConfiguration.ValidationStrategy == ValidationStrategy.Annotations &&
endpoint != null && !endpoint.Metadata.OfType<FluentValidationAutoValidationAttribute>().Any())
{
HandleUnvalidatedEntries(context);

await next();

return;
Expand Down Expand Up @@ -76,13 +78,7 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE
}
}

if (autoValidationMvcConfiguration.DisableBuiltInModelValidation)
{
foreach (var modelStateEntry in context.ModelState.Values.Where(modelStateEntry => modelStateEntry.ValidationState == ModelValidationState.Unvalidated))
{
modelStateEntry.ValidationState = ModelValidationState.Skipped;
}
}
HandleUnvalidatedEntries(context);

if (!context.ModelState.IsValid)
{
Expand All @@ -96,5 +92,16 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE

await next();
}

private void HandleUnvalidatedEntries(ActionExecutingContext context)
{
if (autoValidationMvcConfiguration.DisableBuiltInModelValidation)
{
foreach (var modelStateEntry in context.ModelState.Values.Where(modelStateEntry => modelStateEntry.ValidationState == ModelValidationState.Unvalidated))
{
modelStateEntry.ValidationState = ModelValidationState.Skipped;
}
}
}
}
}

0 comments on commit 9c95cda

Please sign in to comment.