Hello Web Pages
Now add some Razor code to the example: ## ExampleHello Web Pages
The time is @DateTime.Now
[Run Example Β»](#) The page above contains a line of Razor code marked by the `@` sign. The Razor code does all the work on the server, and produces the result displayed. (You can specify formatting options, otherwise the default will be used.) * * * ## Main Razor C# Syntax Rules * Razor code blocks are enclosed in `@{ ... }` * Inline expressions (variables and functions) start with `@` * Code statements end with semicolons * Variables are declared with the `var` keyword * Strings are enclosed with quotation marks * C# code is case sensitive * C# files have the extension `.cshtml` ## C# Example @{ var myMessage = "Hello World"; }The value of myMessage is: @myMessage
@{ var greeting = "Welcome to our site!"; var weekDay = DateTime.Now.DayOfWeek; var greetingMessage = greeting + " Today is: " + weekDay; }The greeting is: @greetingMessage
[Run Example Β»](#) * * * ## Main Razor VB Syntax Rules * Razor code blocks are enclosed in `@Code ... End Code` * Inline expressions (variables and functions) start with `@` * Variables are declared with the `Dim` keyword * Strings are enclosed with quotation marks * VB code is not case sensitive * VB files have the extension `.vbhtml` ## Example @Code dim myMessage = "Hello World" End CodeThe value of myMessage is: @myMessage
@Code dim greeting = "Welcome to our site!" dim weekDay = DateTime.Now.DayOfWeek dim greetingMessage = greeting & " Today is: " & weekDay End CodeThe greeting is: @greetingMessage
[Run Example Β»](#) * * * ## More About C# and Visual Basic If you want to learn more about Razor, C#, and Visual Basic programming languages, please see the (#) of this tutorial.
YouTip