Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call RenderSection twice ...?

I have an ASP.NET-MVC3-Layout and use the RenderSection function:

@RenderSection("BackLink", required: false)

How can I call this function twice? I want to render a defined section at multiple places in my layout.

If I use @RenderSection() more than once I get an error.

like image 472
Konrad Avatar asked Oct 28 '11 15:10

Konrad


People also ask

Can we have multiple RenderBody method in a view?

There can only be one RenderBody method per Layout page.

Can we have multiple RenderBody in MVC?

Multiple RenderBody() methods are NOT allowed in a single layout view. Multiple RenderSection() methods are allowed in a single layout view. The RenderBody() method does not include any parameter. The RenderSection() method includes boolean parameter "required", which makes the section optional or mandatory.

What is RenderBody () in asp net?

RenderBody() is called to render the content of a child view. Any content on said view that is not in a @section declaration will be rendered by RenderBody() . Using the Layout view above, that means that all content in a child view will be rendered inside the <div class="container body-content"> .

What is RenderSection and RenderBody in MVC?

RenderBody is required, as it's what renders each view. RenderSection has an optional parameter that lets you mark the section as not required.


1 Answers

Maybe something like:

@var result = RenderSection("BackLink", required: false).ToHtmlString();

First:
@Html.Raw(result);

Second:
@Html.Raw(result);
like image 134
Paul Tyng Avatar answered Oct 07 '22 11:10

Paul Tyng