My problem is I can\'t seem to use @RenderSection
from a nested template when @RenderSection
is defined in the base template. Currently, I have a
You need to specify the sections that are allowed to pass through in the middle template.
BaseTemplate.cshtml
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
@RenderSection("HeaderContent", false) @* The region of the header scripts (custom css) *@
</head>
<body>
@RenderBody()
</body>
</html>
EDIT
your new child template
@{
Layout = "~/Views/Shared/BaseTemplate.cshtml";
}
@section HeaderContent {
@RenderSection("HeaderContent", false)
}
@RenderBody()
If you put the render section inside of a section from the base template, it will render that section in the correct place on the base template.
View.cshtml -> uses MiddleLayout.cshtml as it's layout
@section HeaderContent
{
<!-- header content that will now render -->
}
<!-- page content -->