开发者

Extra menu for one of controllers

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")
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜