ActionFilterAttribute is an ASP.NET Core abstract base class for synchronous and asynchronous MVC action- and result-filter behavior. Derive from it when a filter needs only selected lifecycle methods. section 22.1.3
Action filters run after model binding, so ModelState contains validation results. Assigning context.Result short-circuits action execution and later action filters while the remaining pipeline continues. section 22.1.3
Validate invalid model state
Override OnActionExecuting, test context.ModelState.IsValid, and assign BadRequestObjectResult(context.ModelState) when validation fails. This moves repeated controller checks into the filter pipeline. section 22.1.3
Return 404 for a missing entity
An EnsureRecipeExistsAttribute retrieves RecipeService from request services, reads the action's id argument, and assigns NotFoundResult when the entity is absent.
