I have some base layout with site structure. In this default layout I define header tag, body structure and footer:
<html>
<head>...</head>
<body>
<div id="sidebar">...</div>
<div id="entry">@RenderSection("Entry", true)</div>
<div id="footer">...</div>
</body>
Each action in each controller defines in their view own entry section.
<!-- in View/Index.cshtml -->
@section Entry {
Hello from Index action.
}
<!-- in View/Uploads.cshtml -->
@section Entry {
Hello from Uploads action.
}
<!-- in View/Users.cshtml -->
@section Entry {
Hello from Users action.
}
But I also want define different sidebars for each controller. If I put @RenderSection(“SideBar”, true) in main layout I must repeat sidebar code for each controllers action. I also can’t define sidebar design code in main layout because I want use different sibebars for each controller (but I want use same sidebar for each action in controller).
How can I solve this problem without repeating sidebar design code in each view?
I find solution https://stackoverflow.com/a/5573970 but it will be require duplication base site structure for each controller.
Thanks for answers and sorry for my bad english :(.
Put
@RenderSection("SideBar", false)Then you can define the section for certain controller layouts only.
You might want to define separate layouts for each controller and each view in this controller will use controller layout (where you can put your sidebar) instead of default layout. Controller layouts will use default layout.