1

In my master view (_Layout.cshtml) I have a tree-menu.

I want to remove that tree-menu in the main page (home).
The rest of the layout should stay there, I want the body of the home to occupy the space of the tree-menu.

Any efficient in-the-box option?

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632

1 Answers1

4

One approach could be to create a custom view page with a flag for showing/excluding the tree menu.

public class CustomViewPage<T> : WebViewPage 
{
    public bool ShowTreeMenu 
    { 
        get 
        {
            return (ViewBag.ExcludeMenu == null || ViewBag.ExcludeMenu == false);
        }         
    }
}

Inherit the custom class from within the layout file:

@inherits CustomViewPage<dynamic>

Then (In the layout file) only display the tree menu if:

<nav>
@if (ShowTreeMenu)
{ 
    @Html.Partial("_TreeMenu")                            
}
</nav>

And set the flag from the content page when the menu should be excluded:

@{
  ViewBag.Title = "Home Page";
  ViewBag.ExcludeMenu = true;
 }
The Heatherleaf
  • 128
  • 1
  • 2
  • 11