I have one controller called Manager and I want to have additional menu for all views. I need only add something to _Layout.cshtml before and after '@RenderBody()'. How Can I do this using controller/views?
Example:
This is how all of Views from ManagerController now looks like:
开发者_JAVA百科<div id="content">
<h2>Projects Manager</h2>
<p>
Only for admin.
</p>
</div>
@{Html.RenderAction("ManagerMenu", "Manager");}
I want to change it to (and keep the same result):
<h2>Projects Manager</h2>
<p>
Only for admin.
</p>
How can I do this?
My idea is:
@if ("ProjectManager.Controllers.ManagerController" == ViewContext.Controller.ToString())
{
<div id="content">
@RenderBody()
</div>
{Html.RenderAction("ManagerMenu", "Manager");}
}
else
{
@RenderBody()
}
But I don't know how it should be done properly...
Why not create an optional section, and only implement that section in the Views of the Manager controller?
@RenderSection("ManagerMenu", false);
Then do this in the ManagerController views:
@section ManagerMenu {
@Html.RenderAction("ManagerMenu", "Manager")
}
精彩评论