Briefly describe about razor view engine with a suitable example.
What is Razor View Engine in Asp.Net mvc?
413
04-Feb-2020
Updated on 04-Feb-2020
Nishi Tiwari
04-Feb-2020Razor 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
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:-