liveBook · Manning

IActionModelConvention filter

As explained in Building Web APIs with ASP.NET Core

An IActionModelConvention filter is an ASP.NET Core MVC convention component that modifies the action model during application model construction.

An IActionModelConvention filter changes an action model while ASP.NET Core MVC builds the application model. Applied as an attribute, it can refine framework behavior for one action instead of changing every controller. section 6.2.3

Use the pattern to opt one action out of automatic ModelState validation:

  • Remove ModelStateInvalidFilter, or match its internal factory by type name, then stop searching. section 6.2.3

Selective manual validation

Keep [ApiController] enabled for the application, but decorate the DomainsController Get action with [ManualValidationFilter]. That action can validate ModelState and construct its own validation response while other actions retain automatic validation. section 6.2.3

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Defines the attribute and filter-removal loop, but defers broader filter-pipeline internals.
Examples
Uses ManualValidationFilterAttribute on the DomainsController Get action and manual ValidationProblemDetails responses.
What it assumes
Assumes familiarity with MVC actions and attributes, while demonstrating the convention implementation from the filter class upward.
What you can do after
Apply it via ASP.NET Core MVC to disable automatic validation for one action and implement its response handling manually.
How it connects
Connects action models with ASP.NET Core MVC filters, model validation, ModelState, and ApiController behavior.

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.