razor syntax ASP.NET MVC
www.igifaedit.com
Razor is a view engine that is used in ASP.NET MVC to create dynamic HTML pages. Razor uses a combination of HTML markup and C# or VB.NET code to generate the final output that is sent to the client's browser.
Here are some examples of Razor syntax:
- Outputting plain text or HTML markup:
<p>Hello, World!</p>
- Outputting a variable's value:
<p>My name is @Model.Name</p>
- Using a conditional statement:
@if (Model.Age >= 18) {
<p>You are an adult</p>
} else {
<p>You are a minor</p>
}
- Looping through a collection:
@foreach (var item in Model.Items) {
- @item.Name
}
- Using a helper method:
@Html.ActionLink("Click me!", "Action", "Controller")
- Defining a section of the layout to be replaced by the view:
@section Scripts {
<script src="myscript.js"></script>
}
These are just a few examples of the syntax used in Razor. The Razor syntax is designed to be easy to read and write, and it allows for a lot of flexibility in creating dynamic web pages in ASP.NET MVC.
