I have a twin Layout setup that renders either the entire page (with navigation) or just the contents depending on whether it was an Ajax request or not. I achieve this like so:
_LayoutRightPanel.cshtml
@{
Layout = !Request.IsAjaxRequest() ? "~/Views/Shared/_Layout.cshtml" : null;
}
This works fine for most pages, but pages that are requested via Ajax that contains @section{}
s dont work (they do when loaded normally). I get the following error:
The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_LayoutRightPanel.cshtml": "scripts".
At the bottom of my _LayoutRightPanel I do the following to render scripts, either forcing the section to render on the main layout or rendering it on the current page if its an ajax request
@if (Request.IsAjaxRequest())
{
RenderSection("scripts", false);
}
else{
@section scripts{
@RenderSection("scripts", false)
}
}