0

I'm using a bootstrap template that has sitemap. How to hide a node in Sitemap from a controller. Here is example of My MvcSiteMap. I want to hide SamplePage Node by a condition in controller.

<mvcSiteMapNode title="Home" clickable="false" icon="fa fa-home" visibility="SiteMapPathHelper,!"></mvcSiteMapNode>
<mvcSiteMapNode title="Dashboard" controller="Dashboard" action="Index" icon="fa fa-dashboard"></mvcSiteMapNode>
<mvcSiteMapNode title="Sample Page" controller="Sample" action="Index" icon="fa fa-info">
  <mvcSiteMapNode title="Master" clickable="false" icon="fa fa-info"></mvcSiteMapNode>
</mvcSiteMapNode>

santro
  • 67
  • 2
  • 10
  • Possible duplicate of [ASP.NET MVC SiteMap provider -- How to 'hide' single items in the actual menu](https://stackoverflow.com/questions/12007065/asp-net-mvc-sitemap-provider-how-to-hide-single-items-in-the-actual-menu) – NightOwl888 May 25 '17 at 20:26

1 Answers1

0

If you want to hide it by condition in your controller, you could achieve it only on this way, you should probably create a property in object that you'r returning from a controller, and that propertly might be called for example :

public static bool HideSamplePage {get; set;}

And what you might do on your View is next (I hope you know that Razor code blocks are enclosed in @{ ... })

@if(Model.HideSamplePage)
{
<mvcSiteMapNode title="Home" clickable="false" icon="fa fa-home" visibility="SiteMapPathHelper,!"></mvcSiteMapNode>
    <mvcSiteMapNode title="Dashboard" controller="Dashboard" action="Index" icon="fa fa-dashboard"></mvcSiteMapNode>
    <mvcSiteMapNode title="Master" clickable="false" icon="fa fa-info"></mvcSiteMapNode>
</mvcSiteMapNode>
}
else
{
  <mvcSiteMapNode title="Home" clickable="false" icon="fa fa-home" visibility="SiteMapPathHelper,!"></mvcSiteMapNode>
    <mvcSiteMapNode title="Dashboard" controller="Dashboard" action="Index" icon="fa fa-dashboard"></mvcSiteMapNode>
    <mvcSiteMapNode title="Sample Page" controller="Sample" action="Index" icon="fa fa-info">
    <mvcSiteMapNode title="Master" clickable="false" icon="fa fa-info"></mvcSiteMapNode>
</mvcSiteMapNode>
}

In code above I said if set state of property HideSamplePage to true, then <mvcSiteMapNode title="Sample Page" controller="Sample" action="Index" icon="fa fa-info"> wont be shown/generated.

else show SamplePage also

Roxy'Pro
  • 4,216
  • 9
  • 40
  • 102