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">
    <meta charset="utf-8" />

    @if (IsSectionDefined("Style"))


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">
  <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; }   


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

Related posts

Recent Viewed