Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RenderSection from partial view

In _Layout.cshtml file I have such method @RenderSection("head", false).

In partial view UploadForm.cshtml I have code below.

When I run web app the head section is not rendered. How to solve this problem?

@section head
{
    <script type="text/javascript">
//skip
    </script>
}
like image 325
Tomas Avatar asked Feb 17 '12 11:02

Tomas


1 Answers

You can only call RenderSection between two Views/Layouts that are directly related. From what you say it looks like your page structure is something like:

UploadForm (section defined here) -> UnknownView -> _Layout (RenderSection called here)

In this situation you would need to essentially redefine and render the section in your View in the middle.

See: http://blogs.msdn.com/b/marcinon/archive/2010/12/15/razor-nested-layouts-and-redefined-sections.aspx for a clearer explanation

like image 106
Simon West Avatar answered Nov 03 '22 09:11

Simon West