Chapter 9. Extending the controller
This chapter covers
- Understanding the controller extensibility points
- Discovering the requirements for an action
- Using action selectors
- Creating custom action results
- Reducing controller complexity with action results
The ASP.NET MVC framework has a number of extensibility points built into the ControllerBase class, and this chapter will review the out-of-the-box functionality that uses these extensibility points. Additionally, we’ll demonstrate how to use the extensibility points to reduce complexity in controllers.
The ActionResult is one of those extensibility points that can reduce an action’s complexity. We’ll cover how attributes placed on an action method are used to modify its behavior, including action selectors that can determine which action should be executed and action filters that can modify the model returned from an action.
Before covering the extensibility points of the Controller and ControllerBase base classes, it’s important to learn that the controller is an extensibility point of its own. If your project requires additional flexibility that isn’t supported out of the box, you’re not out of luck—the MVC Framework gives you full control to implement your own controller, which could act radically differently than the one provided in the framework.