Custom Hide Sidemap MVC

257 Views Asked by At

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>

1

There are 1 best solutions below

1
Roxy'Pro On

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