Tomas
Tomas

Reputation: 18107

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>
}

Upvotes: 6

Views: 10912

Answers (1)

Simon West
Simon West

Reputation: 3788

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

Upvotes: 9

Related Questions