Saurabhchauhan232
Saurabhchauhan232

Reputation: 89

Multiple content placeholders in mvc?

<div class="welcome">                      
      <asp:ContentPlaceHolder runat="server" ID="FeaturedContent" />
      <div style="margin: 10px 0;">
          <asp:ContentPlaceHolder runat="server" ID="MainContent" />
      </div>
      <!-- etc -->
</div>

I have master page in asp.net project which have two content place holder? Now i am trying to create. this project in MVC how to to take two content place holder in _Layout.cshtml. So at derived page i can put my content's in between this.

Upvotes: 5

Views: 2722

Answers (2)

Saurabhchauhan232
Saurabhchauhan232

Reputation: 89

 <div class="welcome">                      
                     @RenderSection("featured", required: true)
                        <div style="margin: 10px 0;">
                              @RenderSection("MainContent", required: true)
                        </div>
                                @RenderBody()
                        <div class="c">
                        </div>
                    </div>

and in inherited page

@section MainContent
{
    <h1>MainContent</h1>
}
@section featured
{
    <h1>feaured</h1>
}

Thank You Kumar Manish

Upvotes: 1

Kumar Manish
Kumar Manish

Reputation: 3772

Razor also supports the ability to add additional "named sections” to layout templates as well. These sections can be defined anywhere in the layout file (including within the section of the HTML), and allow you to output dynamic content to multiple, non-contiguous, regions of the final response.

Read below link : http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx enter image description here

Upvotes: 2

Related Questions