ContentPlaceHolder in Razor?

2019-01-14 05:31发布

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>

2条回答
可以哭但决不认输i
2楼-- · 2019-01-14 05:40

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

@RenderSection("footer", false)
查看更多
小情绪 Triste *
3楼-- · 2019-01-14 05:55

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. 

}
查看更多
登录 后发表回答