Chapter 16. Extending the controller
This chapter covers
You now know all the basics of ASP.NET MVC, and you understand all the parts necessary to build compelling web applications. Let’s go further. The ASP.NET MVC framework has a number of extensibility points built in, and this chapter focuses on those that can be used in controller classes. Not only does extending the controller provide flexibility, it also reduces complexity.
We’ll cover how the basic notion of a controller provides for extension. Then we’ll explore how to extend actions and how a controller selects them. Finally, we’ll develop a custom action result to reduce complexity in the action.
If, at the end of this chapter, you find that the extension points aren’t sufficient, 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.
The default controller implementation comes with some specific ideas about how action methods are selected, executed, and extended. This functionality comes from the Controller base class in the ASP.NET MVC framework, which is the default implementation of the IController interface.