In this recipe, you will learn how to create and use action filters.
An action filter injects business logic before and/or after the action filter is executed. It usually checks and/or modifies elements of the request; for example, parameters and headers. Action filters can also check model bindings. A model binding sets values of UI elements (such as textbox
, combobox
, checkbox
, and so on) by an instance of a class, and gets values of UI elements to the instance of a class. If a class is used to get/set values of UI elements, that class is called a ViewModel
. The model binding mechanism binds the ViewModel
and UI layer automatically.
To create our own action filter, we have to create a class that derives from any of the following base classes or interfaces:
IActionFilter
orIAsyncActionFilter
, depending on whether we want to create a synchronous or an asynchronous filterActionFilterAttribute...