asp.net-mvcRazor


Introduction

What is Razor?

Razor is a markup syntax that lets you embed server-based code (Visual Basic and C#) into web pages.

Server-based code can create dynamic web content on the fly, while a web page is written to the browser. When a web page is called, the server executes the server-based code inside the page before it returns the page to the browser. By running on the server, the code can perform complex tasks, like accessing databases.

Syntax

  • @{ ... }
  • @variableName
  • @(variableName)
  • @for(...){ }
  • @(Explicit Expression)
  • @* comments *@

Remarks

ASP.NET Razor includes view engines for both C# and VB.

The C# view engine processes files with a .cshtml extension, while the VB view engine works with .vbhtml files.