Chapter 3. View fundamentals
This chapter covers
Views are a critical part of an ASP.NET MVC application—they provide a clean way to separate presentation concerns from the logic in your application. In the last chapter, we looked briefly at some simple views written with the Razor templating engine for our Guestbook application, and we ended the chapter by looking at how layouts can be used to apply a standard look and feel to all pages in an application.
In this chapter, we’ll look at views in a bit more depth—we’ll examine how ASP.NET MVC renders views and look at the different options available for passing data to views. Finally, we’ll cover the templating features that were originally introduced in ASP.NET MVC 2. To illustrate these features, we’ll begin to look at adding an edit page to the Guestbook application.
The view’s responsibility can be deceptively simple. Its goal in life is to take the model given to it and use that model to render content. Because the controller and related services already executed all the business logic and packaged the results into a model object, the view only needs to know how to take that model and turn it into HTML.