Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

asp.net mvc - ContentPlaceHolder in Razor?

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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. 

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...