MVC 3 Rendering a section in a area

1.2k Views Asked by At

I am trying to render a section that is defined in _layout file from my custom area.

In my area I have the _ViewStart which points to the _layout in the root site.

The section that I am trying to use is in the head tag, but in my area it is put in the body.

Page that are rendered at the root level work fine.

~/Views/Shared/_Layout.cshtml

<head>

    @RenderSection("header", true)
</head>
<body>
 ....
</body>

~/Areas/UserMedia/Views/_ViewStart.cshtml

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

~/Areas/UserMedia/Views/ManageProjectMedia.cshtml

@{
    ViewBag.Title = "ManageProjectMedia";
}

@section header{
{
<!-- scripts and styles -->
}

<div>
 ... page content
</div>
1

There are 1 best solutions below

1
On BEST ANSWER

On your question you pointed out a code sample whose path is ~/Views/_layout.cshtml and on your _ViewStart.cshtml file under your area, you have the following code :

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

I am sure you will find the seven difference here :)

Seven difference thing was a joke but anyway. Your _Layout.cshtml is sitting under ~/Views/ but you're referencing _Layout.cshtml which is under ~/Views/Shared/.