Easy Tutorial
❮ Prop Webcontrol Radiobuttonlist Repeatcolumns Prop Webcontrol Textbox Text ❯

ASP.NET Web Pages - Adding Razor Code


In this tutorial, we will use Razor markup with C# and Visual Basic code.


What is Razor?


Adding Razor Code

Remember the webpage from the previous chapter's example:

Now, add some Razor code to the example:

Example @DateTime.Now

This page contains regular HTML markup, along with Razor code identified by the @ symbol.

Razor code performs all actions on the server in real-time and displays the results. (You can specify formatting options, otherwise, it will display the default.)


Main Razor C# Syntax Rules

C# Example

@{ var myMessage = "Hello World"; }
@myMessage

@{
var greeting = "Welcome to our site!";
var weekDay = DateTime.Now.DayOfWeek;
var greetingMessage = greeting + " Today is: " + weekDay;
}
@greetingMessage

Main Razor VB Syntax Rules

VB Example

@Code dim myMessage = "Hello World" End Code
@myMessage

@Code
dim greeting = "Welcome to our site!" 
dim weekDay = DateTime.Now.DayOfWeek 
dim greetingMessage = greeting & " Today is: " & weekDay
End Code
@greetingMessage

More About C# and Visual Basic

If you want to learn more about Razor, C#, and Visual Basic programming languages, please check out the Razor section of this tutorial.

❮ Prop Webcontrol Radiobuttonlist Repeatcolumns Prop Webcontrol Textbox Text ❯