Chapter 3Views

—by Phil Haack and Jon Galloway

What's In This Chapter?

  • The purpose of views
  • Understanding view basics
  • View conventions 101
  • All about strongly typed views
  • Understanding view models
  • How to add a view
  • Using Razor
  • How to specify a partial view


All code for this chapter is provided via NuGet, as described in the introduction at the front of this book. NuGet code samples will be clearly indicated via notes at the end of each applicable section. You can also visit for offline use.

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 forms 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.

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 might well be.

In this chapter, we won't show you how to make a pretty view. Visual design is a separate concern from rendering content, although clean markup can make your ...

Get Professional ASP.NET MVC 5 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.