Given this nested layout structure:
~/Views/Shared/_layoutBase.cshtml ~/Views/Shared/_layout.cshtml
Where _layoutBase.cshtml
i
I am unable to reproduce the problem. Here's my setup and steps I did.
Add ~/Views/Shared/_LayoutBase.cshtml
:
<!DOCTYPE html>
<html>
<body>
@RenderBody()
<script type="text/javascript">
@RenderSection("footerScripts", false)
</script>
</body>
</html>
Replace the contents of ~/Views/Shared/_Layout.cshtml
with this:
@{
Layout = "~/Views/Shared/_LayoutBase.cshtml";
}
@section footerScripts{
@RenderSection("footerScripts", false)
}
@RenderBody()
Right click on the project and add an Admin area
Add a TestController to this admin area and add a corresponding ~/Areas/Admin/Views/Test/Index.cshtml
view:
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
@section footerScripts{
alert('ok');
}
/admin/test/index
I have got up this morning and saw the problem straight away:
I had the @section blocks in a Partial View. In MVC 3, that WON'T work!!
ARGH!
I really appreciate Darin's effort, that effectively provided proof that sections do work in Areas as expected. But the real cause was this.
I forgot they were in a Partial View, because I have a mvc 3 wizard that uses partial views for steps. It works so well and consistently, using ajax if javascript is available, that you forget what you are doing.
Please give Darin a vote, but this is the real answer.