<h1>Razor syntax demo</h1>
<p>Demo 1</p>
<h2>@DateTime.Now.ToShortDateString()</h2>
<p>Demo 2</p>
@{
var date = DateTime.Now.ToShortDateString();
var message = "Hello World";
}
<h2>Today's date is: @date </h2>
<h3>@message</h3>
<p>Demo 3</p>
@{
var date1 = DateTime.Now.ToShortDateString();
string message1 = "Hello World!";
@:Today's date is: @date1
<br />
@message1
}
<p>Demo 4</p>
@{
var date2 = DateTime.Now.ToShortDateString();
string message2 = "Hello World!";
<text>Today's date is:</text> @date2
<br />
@message2
}
<p>Demo5if-else condition:</p>
@if (DateTime.IsLeapYear(DateTime.Now.Year))
{
@DateTime.Now.Year @:is a leap year.
}
else
{
@DateTime.Now.Year @:is not a leap year.
}
<p>Demo 6</p>
for loop:
@for (int i = 0; i < 5; i++)
{
@i.ToString()
<br />
}
<p>Demo 7</p>
Declare Variables
@{
string str = "";
if (1 > 0)
{
str = "Hello World!";
}
}
<p>@str</p>
<p>Demo 8</p>
Model
@model MVCDemo.Models.PersonalDetail
@Model.FirstName
No comments:
Post a Comment