InterviewSolution
| 1. |
What is Razor View Engine? |
|
Answer» Razor is not a programming language but an HTML markup language which is written on the server side using C#. Razor does not have the tie-up with Asp.net mvc. It has implemented a view engine to use razor view to produce the HTML output. It USES the @{....} syntax. It uses a semicolon to end the statement, it has .cshtml as file extensions.inline expression also uses the @ expression’ Conditions with if statement It starts with a code block and its condition is written in parenthesis. the code which needs to be executed is written inside braces. @{var Price=60;} <html> <BODY> <if(Price>60) { <p>This is paragraph</p> } </body> </html>In the above example, we have declared var price has a value of 60 and we are using if statement which is validating price. the code written in side braces gets executed,if price value is greater than 50. In razor, we have a different type of block statements available, which are 1.Single Statement Block and Inline Expression: It is the same as we DISCUSSED above that it is the block of code which is executed in the single line statement. @{var series=4;} <p>MVC series :@series</p> <p>Razor Message:@RazorMessage</p>2.Multiple Statement Block with Inline Expressions : In this we DECLARE all the variable in single @{....} and each variable is ended with the semi colon @{ Var a =”This is Razor Syntax”; Var b = DateTime.Now.DayOfWeek; Var c = a + “Date on ”+b; } <p>Razor Message:@HomeMessage</p>So it is better to declare the variable at the top of the view because if we declare the variable at the top then it can be USED in all inline block of statement written on that view and if we declare this variable at the middle order of view then we cannot use at the top statement written in @{....}. |
|