Bri Manning

The Razor ASP.NET MVC Engine and Iterating Software

April 25, 2011

I recently starting working on a project that uses the Razor rendering engine. While I had read about it and seen it before, I hadn’t actually used it full-time until this project.

My first real take-away is that it is simply a brilliant enhancement to embedding display code into your views. With the markup being clearly distinguishable from both HTML and JavaScript, the code is far more readable.

The traditional web forms bracket-style notation, originally inherited from classic ASP and in-line with the de facto standard of the day when embedding server-side code into HTML certainly served its purpose, but it quickly becomes apparent that it doesn’t produce the most readable code.

See Razor:

<a href="@Url.Action("Index", "Home")">
    <img src="@Url.Content("~/Content/Images/logo.png")" alt=
        "Logo" />
</a>

Versus Web Forms:

<a href='<%= Url.Action("Index", "Home") %>'>
    <img src=
        '<%= Url.Content("~/Content/Images/logo.png") %>'
        alt="Logo" />
</a>

Thus, the Razor engine solves this problem and makes the front-end code easy to read and distinguish between HTML, JavaScript and server-side, embedded code.