Chapter 6. Views

A user's first impression of your application starts with the View. While your Models may well be elegantly designed, and your Controllers may be well factored and streamlined, none of that is visible to the end users. Their 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, then no amount of spit and polish on the View will make up for the application's deficiencies. However, build an ugly and hard-to-use View, and many users will not give your application the time 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, as our own aesthetic skills may be called into question. 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.

WHAT A VIEW DOES

The View is responsible for providing the user interface (UI) to the user. It is given a reference to the Model, and it transforms that Model into a format ready to be presented to the user. In ASP.NET MVC, this consists of examining the ViewDataDictionary handed off to it by the Controller (accessed via the ViewData property) and transforming that to HTML.

In the strongly typed View case, which ...

Get Professional ASP.NET MVC 2 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.