InterviewSolution
| 1. |
What are Action filters in ASP.NET MVC? |
|
Answer» ACTION filters are the additional ATTRIBUTES in the ASP.NET MVC framework, that we can apply to either a section of the CONTROLLER or to the entire controller for modifying the approach in which action will be executed. Action filter attributes are SAID to be special .NET classes as they are derived from the System.Attribute class and they can be ATTACHED to classes, properties, methods, and fields. The following action filters are provided by ASP.NET MVC:
The below-given code will apply Output cache filter on an ActionFilterExampleController (Here, ActionFilterExampleController is just used as an example, You can apply action filters on any of the controllers). It specifies that the return value should be cached for 20 seconds. public class ActionFilterExampleController: Controller{ [HttpGet] OutputCache(Duration = 20)] public string Index() { return DateTime.Now.ToString("T"); }} |
|