ASP.NET Tutoria...login
ASP.NET Tutorial
author:php.cn  update time:2022-04-11 14:18:18

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 Syntax

Razor uses a similar syntax to PHP and classic ASP.

Razor:

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

<ul>
<?php
for ($i = 0; $i < 10; $i++) {
echo("<li>$i</li>");
}
?>
< /ul>
Web Forms (Classic ASP):

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


Razor Helpers

ASP.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 Language

Razor supports C# (C sharp) and VB (Visual Basic).