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 - C# logical conditions syntax

C# allows conditional execution of code.

Use if statements to determine conditions. According to the judgment result, the if statement returns true or false:

The if statement starts a code block

The condition is written in brackets

If the condition is true, the curly brackets The code inside is executed

Razor - C# logical conditions example

@{var price=50;}
<html>
<body>
@if (price>30)
{
<p>The price is too high.</p>
}
</body>
</html>