Chapter 3

Views

— By Phil Haack

What's in This Chapter?

  • The purpose of Views
  • How to specify a View
  • All about strongly typed Views
  • Understanding View Models
  • How to add a View
  • Using Razor
  • How to specify a Partial View
  • Understanding the View Engine

Developers spend a lot of time focusing on crafting well-factored controllers and model objects, and for good reason because clean well-written code in these areas form the basis of a maintainable web application.

But when a user visits your web application in a browser, none of that work is visible. A user's first impression and entire interaction with your application starts with the view.

The view is effectively your application's ambassador to the user—representing your application to the user and providing the basis on which the application is first judged.

Obviously, if the rest of your application is buggy, no amount of spit and polish on the view will make up for the application's shortcomings. Likewise, build an ugly and hard-to-use view, and many users will not give your application a chance to prove just how feature-rich and bug-free it may well be.

In this chapter, we won't show you how to make a pretty view, because our own aesthetic skills are lacking. Instead, we will demonstrate how Views work in ASP.NET MVC and what their responsibilities are, and provide you with the tools to build Views that your application will be proud to wear.

Get Professional ASP.NET MVC 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.