In an ASP.NET MVC application I have 2 levels of master page inheritance. Page A is super master. Page B is a master page for a portion of the site and inherits from Page A. Page C is just a regular page and inherits from Page B.

I want to be able to specify my own style section in Page C. To that end, I specified '@if (IsSectionDefined("Style")) @RenderSection("Style")` in Page A (the super master). However, when I define a Style section in Page C, it is complaining that its immediate parent (Page B) doesn't specify the Style section.

So my question is how do I get Page B to pass on the Style section from Page A (where it really is defined)?

Here are the specifics and code: The super master page called Site.cshtml. Note that I have @if (IsSectionDefined("Style")) piece to allow the downstream pages define their own style sections.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>

    @if (IsSectionDefined("Style"))
    {
        @RenderSection("Style");
    }

</head>
<body>
   @RenderBody()
</body>
</html>

Then I have a master page which inherits from the one above called Public.cshtml

@{
    Layout = "~/Views/Shared/Site.cshtml";
}
<div data-role="header"></div>
    <div data-role="content" class="allwhite">
        @RenderBody()
    </div>
  <div data-role="footer"></div>

Finally, I have a regular page that inherits from Public.cshtml

@{
    Layout = "~/Views/Shared/Public.cshtml";
}

@section Style
{
    <style type="text/css">             
        ::-webkit-input-placeholder { font-size:12px; }
        ::-moz-placeholder { font-size:12px; } /* firefox 19+ */
        :-ms-input-placeholder { font-size:12px; } /* ie */
        input:-moz-placeholder { font-size:12px; }   
    </style>
}

<h3>Search</h3>

The page blows up complaining that its Layout parent doesn't specify the Style section.

Related posts

Recent Viewed