Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RenderSection() inside partial with master page

I have a partial "Sidebar" added to the master page (Layout) and inside this partial I'm using:

@RenderSection("SearchList", required: false) 

On one of the views that uses the master page I'm doing:

@section SearchList {     // bunch of html } 

but it's giving me the error:

The file "~/Views/Shared/_SideBar.cshtml" cannot be requested directly because it calls the "IsSectionDefined" method.

What's wrong here?

like image 485
raklos Avatar asked Jan 30 '11 18:01

raklos


People also ask

How do I use RenderSection in partial view?

You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html. RenderAction() .

What is the difference between RenderBody and RenderSection in MVC?

RenderBody() renders all the content of the child view which is not wrapped in the named section. RenderSection() renders only a part of the child view which is wrapped under the named section.

What is the function of RenderBody ()?

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"> .

Which of the following is used to render the portion of a content page inside the master page?

RenderBody method exists in the Layout page to render child page/view. It is just like the ContentPlaceHolder in master page.


1 Answers

What you are trying to do is not currently supported in Razor. Sections only work between the view page and its immediate layout page.

like image 188
marcind Avatar answered Sep 22 '22 17:09

marcind