C# 自定义隐藏侧图MVC
我正在使用一个带有站点地图的引导模板。如何从控制器隐藏站点地图中的节点。 下面是我的MvcSiteMap示例。我想根据控制器中的条件隐藏SamplePage节点C# 自定义隐藏侧图MVC,c#,asp.net-mvc,twitter-bootstrap,model-view-controller,mvcsitemapprovider,C#,Asp.net Mvc,Twitter Bootstrap,Model View Controller,Mvcsitemapprovider,我正在使用一个带有站点地图的引导模板。如何从控制器隐藏站点地图中的节点。 下面是我的MvcSiteMap示例。我想根据控制器中的条件隐藏SamplePage节点 <mvcSiteMapNode title="Home" clickable="false" icon="fa fa-home" visibility="SiteMapPathHelper,!"></mvcSiteMapNode> <mvcSiteMapNode title="Dashboard" cont
<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>
如果您想在控制器中按条件隐藏它,您只能通过这种方式实现,您可能应该在从控制器返回的对象中创建一个属性,该属性可能会被调用,例如:
public static bool HideSamplePage {get; set;}
接下来,您可能会对视图执行什么操作(我希望您知道Razor代码块包含在@{…}中)
@if(Model.HideSamplePage)
{
}
其他的
{
}
在上面的代码中,我说过如果将属性HideSamplePage的状态设置为true,
然后将不会显示/生成
否则
显示
SamplePage
也如何在MvcSiteMapNode中设置条件??因为文件是XML格式的?可能是
@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>
}