In InLine Blocks. the razor code is integrated or embedded as part of the HTML as shown below.
[html]
<div>
a=@a
b=@b
s=@s
</div>
[/html]
Note
To write the comments in the Razor view follow the below syntax.
@* Comment 1
Comment 2
Comment 3 *@
Razor is completely
Light Weight Programming Syntax.
Example to Create an array and print the elements.
Write the following code in the
view.cshtml
[html]
@{
ViewBag.Title = "Array Example";
}
@{
Layout = null;
String[] names = new String[4] { "Jan", "James", "Devid", "Loosy" };
}
<h2>Array Example</h2>
<body>
<div>
@foreach(string s in names)
{
@s
}
</div>
</body>
[/html]
Now, write the following code in the
HomeController.cs
[csharp]
public ActionResult view()
{
return View();
}
[/csharp]
In the
RouteConfig.cs, change the Action Method Name as
view and Run the application.
Then, the following output will be displayed in the browser.
Note
All the operators, Selection Statements, Conditional Statements and Looping Statements in Razor are same as in C#.