Razor Views
Razor Views
Razor Views
How to work
with Razor views
Knowledge
3. Distinguish between a Razor code block and inline expressions,
loops, and if statements.
4. Distinguish between an inline conditional statement and an inline
conditional expression.
5. Describe how an MVC web app typically maps its views to the
action methods of its controllers.
6. Describe the use of tag helpers to generate a URL.
A _ViewImports.cshtml file
that enables all ASP.NET Core MVC tag helpers
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<a asp-action="Details"
asp-route-id="Fender-Stratocaster">
View Fender Stratocaster</a>
@ViewBag.DiscountPercent.ToString("P0") 5%
<div class="form-group">
<label asp-for="Price"></label>
<input asp-for="Price" class="form-control">
</div>
<h1>Product List</h1>
@if (ViewBag.Categories != null)
{
foreach (Category c in ViewBag.Categories)
{
<a asp-controller="Product" asp-action="List"
asp-route-id="@c.Name">@c.Name</a>
<text> | </text>
}
}
<a asp-controller="Product" asp-action="List"
asp-route-id="All">All</a>
<hr />
<footer>
<hr />
<p>© @DateTime.Now.Year - Guitar Shop</p>
</footer>
</body>
</html>
@RenderBody()
<footer>
<hr />
<p>© @DateTime.Now.Year - Guitar Shop</p>
</footer>
<h1>Product Manager</h1>
@if (ViewBag.Categories != null)
{
foreach (Category c in ViewBag.Categories)
{
<a asp-controller="Product" asp-action="List"
asp-route-id="@c.Name">@c.Name</a><text> | </text>
}
<a asp-controller="Product" asp-action="List"
asp-route-id="All">All</a>
}
<hr />
@RenderBody()
<footer>
<hr />
<p>© @DateTime.Now.Year - Guitar Shop</p>
</footer>
@section scripts {
<script src="~/lib/jquery-validate/jquery.validate.min.js">
</script>
<script src="~/lib/jquery-validation-unobtrusive/
jquery.validate.unobtrusive.min.js">
</script>
}
<h2>Update</h2>
// the HTML elements for the rest of the view body go here
<script src="~/lib/jquery/jquery.min.js"></script>
<script src="~/lib/popper.js/popper.min.js"></script>
<script src="~/lib/bootstrap/js/bootstrap.min.js"></script>
@RenderSection("scripts", false)
</head>
<body>
@RenderBody()
</body>
</html>