Mimic ContentPlaceHolder to define content inside RenderSection declaration

So, using the aspx rendering engine for the MVC3 framework, it is easy to define a section in the master layout page and insert html or asp code inside those sections that will appear on every page, like so:

On the master layout

<!-- Secondary content -->
<div id="content-secondary">
  <asp:ContentPlaceHolder ID="NavigationSecondary" runat="server">
    <% Html.RenderAction("Menu", "Navigation", new { @id = "nav-secondary"}); %>
  <asp:ContentPlaceHolder ID="cphSecondary" runat="server" />
<!-- /Secondary content -->

You can see that a Menu is rendered inside the ContentPlaceHolder called NavigationSecondary. So on every page that I create, the menu is displayed by default and any other extra content is displayed below that.

Now, how would I interpret this in the Razor engine? I couldn't find much info online. I did find something that shows how to use default content. But would that default content be erased when inserted with content from another page?


Razor view engine allows checking (in _Layout.cshtml) if layout section has been implemented by views so with this you could mimic putting code inside ContentPlaceHolder.

<div id="content-secondary">
    @if (IsSectionDefined("NavigationSecondary"))
        Html.RenderAction("Menu", "Navigation", new {@id = "nav-secondary"});

Hope this is what you are looking for.

Need Your Help

How I can put "Imagenview" under all the elements?

android android-layout android-xml

Hi, I commented that I have this layout and if you can see there is a line on the right which should go below the text

Gnuplot behaves oddly in polynomial fit. Why is that?


A friend of mine discovered some odd behavior in gnuplot regarding a simple polynomial fit Can sombody explain this?