About

Razor is a template language used by ASP.NET Web Pages and ASP.NET MVC (since version 3). It supports seamless transitions between HTML markup and C# or VB code. Transitions between markup and code are indicated by the "@" sign.

For example, to render a simple HTML list, this c# syntax is used:

<ul>
@for (int i = 0; i < 10; i++) {
    <li>Item @i</li>
}
</ul>

To render a simple HTML list in VB, this syntax is used:

<ul>
@For i As Integer = 0 To 9
    @<li>Item @i</li>    
Next
</ul>

Razor has support for helper templates:

@helper Bold(string text) {
   return "<bold>"+text+"<bold>";
}

<p>
  This text is @Bold("bold")
<p> 

By default all string are html encoded, if you wish to avoid that use the Raw helper:

<p>@Html.Raw("<bold>hello</bold>")</p>

Occasionally you may want to include text in an escaped section, to do so use <text> or @::

@if(something) {
 @: This is going to be rendered
}

@if(something) {
 <text>
   This is a 
   Multiline text block 
 </text>
} 
history | show excerpt | excerpt history