Please briefly describe different types of block statements used in razor in MVC.
Explain different types of block statements in Razor view Engine?
49704-Feb-2020
Updated on 04-Feb-2020
Home / DeveloperSection / Forums / Explain different types of block statements in Razor view Engine?
Please briefly describe different types of block statements used in razor in MVC.
Nishi Tiwari
04-Feb-2020In razor view engine has a different type of block statements are available:-
Single Statement Block and Inline Expression
We define code in opening and closing curly brackets @{...} and single statement block code will be like this
Multiple Statement Block and Inline Expression
Here, in multiple statement block, we will define all variables in single curly brackets @{...} so we must need to end each variable with a semicolon and our multiple statement block code will be shown like below:-
Usually, in razor engine code written at top of view will be accessible in any other code block in same view page else in case if we will declare a variable in middle and try to access a top we will not be able to access those variables and it will throw an error as it shows:-
We observe in the above code we tried to access variable "i" before declaring that is the reason it throws an error as shown above.