ASP.Net Razor Syntax Rules and Working

Razor syntax role for C#

  1. Variable and functions with inline property must start with the @
  2. Variables are declared with the var keyword
  3. Razor block having C# code always enclosed with in @{….}
  4. Code statements always end with semicolon
  5. C# file will have the extention “cshtml”
Working of  Razor code

Razor code syntax completely based on ASP.Net framework. It is  part of the Microsoft.NET Framework that is specially designed for creating web applications. The most important thing about the Razor is that the syntax gives developer all the power of ASP.NET, but it use a simplified syntax .

Razor is very simple programming syntax for embedding server code in web pages. When a web page having razor code describeed as a html page we found two type of content

  1. Normal HTML Content
  2. Razor Code.

It is the Razor code that runs first whenever the sever reads the page. After this only the server sends the HTML page to webbrowser. Sometimes there may be the condition that code that is executed on the server can perform tasks that cannot be perform in the web browser.

ASP.NET web pages that contain Razor code have the special file extension cshtml (Razor using C#) .