Sunday, January 16, 2011

Razor – view engine for ASP.NET

Razor is a new view engine for ASP.NET. We know that view engines are pluggable modules that implement different templates syntax options. We have .aspx/.ascx/.master as the default view engine for ASP.NET MVC. This is optimized around HTML generation using a code-focused templating approach. “Razor” uses a new file suffix “cshtml” or “vbhtml”, where the prefix is the language used in the file.

Razor has the following features

  • Razor minimizes the number of characters in coding which brings a cleaner server side code.
  • Easy to learn and use the existing coding skills
  • Works in any text editor
  • Full intellisense support in Visual Studio 2010

Let’s examine how the new Razor syntax looks like. Following the common server side code snippet

    <% foreach(var student in students) %>

    <%{%>

    <% student.Name %>

    <%}%>

Now we have the following simple Razor syntax as follows.

    @ foreach(var student in students)

    {

    @ student.Name

    }

Hey it gives a clean server side code.

No comments:

Post a Comment

Installing ASP.NET MVC

Installing ASP.NET MVC Before we dive deep into the ASP.NET MVC, let’s install it our development machine. This is very straight forwa...