Other View Features
To finish this chapter, I will show you some other features that Razor views support. These don't follow any single theme; they are just useful things to know that can make development easier.
Razor Sections
When I described the @RenderBody
tag, I explained that it is used in a layout to insert the contents of the view, except those parts that are in a named section. Listing 25-30 shows the List.cshtml
view reworked to include some sections.
Listing 25-30. Defining sections in a Razor view
@model IEnumerable<EventRegistration.Models.Domain.Registration>
@{
ViewBag.Title = "List";
Layout = "~/Views/Shared/CustomLayout.cshtml";
}
@section Header {
<h4>
@switch (Model.Count()) {
case 0: ...
Get Applied ASP.NET 4 in Context now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.