Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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> 
like image 873
jgauffin Avatar asked Nov 12 '10 09:11

jgauffin


People also ask

What is ContentPlaceHolder?

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.

What is razor pages in .NET core?

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 in Visual Studio?

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.


2 Answers

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.   } 
like image 176
jgauffin Avatar answered Oct 11 '22 12:10

jgauffin


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

@RenderSection("footer", false) 
like image 28
Kyle Avatar answered Oct 11 '22 13:10

Kyle