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>
A ContentPlaceHolder control defines a relative region for content in a master page, and renders all text, markup, and server controls from a related Content control found in a content page. A Content control is associated with a ContentPlaceHolder using its ContentPlaceHolderID property.
Razor pages are simple and introduce a page-focused framework that is used to create cross-platform, data-driven, server-side web pages with clean separation of concerns.
What is Razor? Razor is a markup syntax that lets you embed server-based code (Visual Basic and C#) into web pages. Server-based code can create dynamic web content on the fly, while a web page is written to the browser.
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. }
Couldn't leave a comment sorry but you can remove the "required:"
@RenderSection("footer", false)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With