Razor view engine in asp.net MVC is defined as a syntax that allows us to write server-side code on view.
Razor helps to combine code and Html in a fluid manner. It is not a new programming language if we know C#, Vb.Net and bit HTML we can easily write Razor code. It supports C# and Visual Basic programming languages.
A Razor syntax is based on C# programming language and the code statements in Razor end with a semicolon (;) which would be shown below.
Syntax of Razor View Engine
Usually, in razor view engine code blocks are enclosed in "@{ ... }". This “@” is a character that tells the beginning of Razor syntax. These codes can be a single expression or an entire code block. This syntax represents razor view engine declaration in asp.net MVC
@{
//Razor block
}
The above code "@{"a character tells the beginning of the block and "}" a character tells the ending of the block.
Declaring a variable in Razor View
We will declare the razor view engine as shown below:-
@{
var weekDay = DateTime.Now.DayOfWeek;
}
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Razor view engine in asp.net MVC is defined as a syntax that allows us to write server-side code on view. Razor helps to combine code and Html in a fluid manner. It is not a new programming language if we know C#, Vb.Net and bit HTML we can easily write Razor code. It supports C# and Visual Basic programming languages.
A Razor syntax is based on C# programming language and the code statements in Razor end with a semicolon (;) which would be shown below.
Syntax of Razor View Engine
Usually, in razor view engine code blocks are enclosed in "@{ ... }". This “@” is a character that tells the beginning of Razor syntax. These codes can be a single expression or an entire code block. This syntax represents razor view engine declaration in asp.net MVC
@{
//Razor block
}
The above code "@{"a character tells the beginning of the block and "}" a character tells the ending of the block.
Declaring a variable in Razor View
We will declare the razor view engine as shown below:-
@{
var weekDay = DateTime.Now.DayOfWeek;
}