MVC3 ASP.NET - Introduction to Razor View Engine

The latest release of Microsoft’s ASP.Net MVC is now shipped with a brand new view engine called Razor. This brand new syntax is responsible for parsing and compiling your views and partial views into C# so as to be able to render the view into HTML markup. It reads more like a devlopment language like C# rather than the old Classic ASP style scripting. It’s also very easy to learn.

This example is the old way of displaying a For Each loop using the traditional scripting syntax



Here is the same block of code using the new Razor syntax



You'll notice that the @ symbol is the new delimiter. You'll also notice that there is no closing delimiter. The Razor engine is extremely smart at figuring out the end of any code you write in your markup. There is also full  intellisense support for Razor in Visual Studio giving you a helping hand along the way.

I find as the page becomes more complex, the more Razor helps your code to be much cleaner with greater readability and with the bonus of having to write less to achieve this.