Introduction to Razor
ASP.NET Razor - Tags
##Razor is not a programming language. It is a server-side markup language.
What is Razor? Razor is a markup syntax that allows you to embed server-based code (Visual Basic and C#) into web pages. Server-based code creates dynamic web content as the web page is delivered to the browser. When a web page is requested, the server executes the server-based code in the page before returning the page to the browser. Run by the server, the code can perform complex tasks, such as accessing a database. Razor is based on ASP.NET and is designed for creating web applications. It has the functionality of traditional ASP.NET, but is easier to use and easier to learn.
Razor SyntaxRazor uses a similar syntax to PHP and classic ASP. Razor:
<ul>
PHP:@for (int i = 0; i < 10; i++) {
<li>@i< /li>
}
</ul>
<li>@i< /li>
}
</ul>
<ul>
Web Forms (Classic ASP):<?php
for ($i = 0; $i < 10; $i++) {
echo("<li>$i</li>");
}
?>
< /ul>
for ($i = 0; $i < 10; $i++) {
echo("<li>$i</li>");
}
?>
< /ul>
<ul>
<% for (int i = 0; i < 10; i++) { %>
<li><% =i %></li>
<% } %>
</ul>
<li><% =i %></li>
<% } %>
</ul>
Razor HelpersASP.NET helpers are components that can be accessed with a few simple lines of Razor code. You can build your own helper using Razor syntax, or use the built-in ASP.NET helper. Here are brief descriptions of some useful Razor helpers:
- Web Grid
- Web Graphics
- Google Analytics
- Facebook Integration
- Twitter Integration
- Sending Email
- Validation
Razor Programming LanguageRazor supports C# (C sharp) and VB (Visual Basic).