Chapter 17. Advanced view techniques
This chapter covers
The MVC pattern gives us separation of concerns between the model, controller, and view, but this pattern didn’t eliminate the need for developers to carefully design their views. You saw in the last chapter how you can use controller extension points to build clean, easy-to-modify controllers. With the elimination of code-behind and the addition of a view model object, you can focus strictly on rendering content inside your view. But without careful attention, your views can still slide into a morass of duplication and spaghetti code. You can no longer lean on custom controls to encapsulate view behavior as you did in Web Forms. Instead, ASP.NET MVC provides similar and expanded mechanisms for tackling all levels of duplication in your views.
In this chapter, we’ll first explore various means of eliminating the various forms of duplication in our applications. Next, we’ll examine how subtle bugs can arise when generating URLs for action methods that include parameters, and we’ll look at a strategy for eliminating those bugs. Finally, we’ll take a tour of the Spark view engine and see how its syntax and capabilities make it an excellent alternative to the built-in view engines.