about 9 years ago
Razor is a syntax which add server-based code to web pages. Razor engine in .NET is used in place of ASP engine for running applications.
The page contains ordinary HTML markup, with one addition the @marked Razor code.
See the example below:
- <!-- Single statement block -->
- @{ var myMessage = "Himanshu Joshi"; }
- <!-- Inline expression or variable -->
- <p>The value of myMessage is: @myMessage</p>
- <!-- Multi-statement block -->
- @{
- var greeting = "Welcome to our site!";
- var weekDay = DateTime.Now.DayOfWeek;
- var greetingMessage = Hello + " Today is: " + weekDay;
- }
- <p>The greeting is: @greetingMessage</p>
<!-- Single statement block --> @{ var myMessage = "Himanshu Joshi"; } <!-- Inline expression or variable --> <p>The value of myMessage is: @myMessage</p> <!-- Multi-statement block --> @{ var greeting = "Welcome to our site!"; var weekDay = DateTime.Now.DayOfWeek; var greetingMessage = Hello + " Today is: " + weekDay; } <p>The greeting is: @greetingMessage</p>
Output of above code will be:
The value of myMessage is: Himanshu Joshi
The greeting is: Hello Today is Monday
With Web Pages you can use the @RenderPage() method to import content from separate files.
See the example below:
The output of above code will be:
This is a header from a separate file
This is my Web Pages
This is a paragraph
This is a footer from a separate file
0 Comment(s)