O'Reilly logo

Professional ASP.NET MVC 3 by K. Scott Allen, Brad Wilson, Phil Haack, Jon Galloway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Razor View Engine

The previous two sections looked at how to specify a view from within a controller as well as how to add a view. However they didn't cover the syntax that goes inside of a view. ASP.NET MVC 3 includes two different view engines, the new Razor View Engine and the older Web Forms View Engine. This section covers the Razor View Engine which includes the Razor syntax, layouts, partial views, and so on.

What is Razor?

The Razor View Engine is new to ASP.NET MVC 3 and is the default view engine moving forward. This chapter focuses on Razor and does not cover the Web Forms View Engine.

Razor is the response to one of the most requested suggestions received by the ASP.NET MVC feature team—to provide a clean, lightweight simple view engine that didn't contain the “syntactic cruft” contained in the existing Web Forms View Engine. Many developers felt that all that syntactic noise required to write a view created friction when trying to read that view.

This request was finally answered in version 3 of ASP.NET MVC with the introduction of the new Razor View Engine.

Razor provides a streamlined syntax for expressing views that minimizes the amount of syntax and extra characters. It effectively gets out of your way and puts as little syntax as possible between you and your view markup. Many developers who have written Razor views have commented on feeling the view code just flowing from their fingertips, akin to a mind-meld with their keyboard. This feeling is enhanced with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required