ContentPlaceHolder in Razor?

asp.net MvcRazor

asp.net Mvc Problem Overview


I can use ContentPlaceHolder's with Webforms view engines to put stuff in different locations in the master page.

How do I do that with Razor?

    <div id="content">
        <asp:ContentPlaceHolder ID="MainContent" runat="server">
        </asp:ContentPlaceHolder>
    </div> 
    <div id="footer">
        <asp:ContentPlaceHolder ID="Footer" runat="server">
        </asp:ContentPlaceHolder>
    </div>

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

Yet again I managed to ask before finding the correct search keywords in Google.

In the layout

@RenderSection("footer", required: false)  

View example

<h2>About</h2> 
    
<p>   
    Some stuff about this page.   
</p> 

<p> 
    The current date and time: @DateTime.Now  
</p> 
    
@section footer { 

    Copyright (c) 2010, Robert Sundström. 

}

Solution 2 - asp.net Mvc

Couldn't leave a comment sorry but you can remove the "required:"

@RenderSection("footer", false)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjgauffinView Question on Stackoverflow
Solution 1 - asp.net MvcjgauffinView Answer on Stackoverflow
Solution 2 - asp.net MvcKyleView Answer on Stackoverflow