ASP.NET MVC SiteMap提供程序-如何在实际菜单中“隐藏"单个项目 [英] ASP.NET MVC SiteMap provider -- How to 'hide' single items in the actual menu

查看:85
本文介绍了ASP.NET MVC SiteMap提供程序-如何在实际菜单中“隐藏"单个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目中使用ASP.NET MVC SiteMap提供程序,并且运行良好.我正艰难地试图弄清楚如何隐藏菜单项.我想从全局导航中隐藏的菜单项是站点地图"页面.现在我知道在mvcSiteMapNode上有一个叫做VisibilityProvider的东西可供我使用-但我似乎无法弄清楚如何使其工作.

I am using the ASP.NET MVC SiteMap provider in a project, and it is working great. I am having a tough time trying to figure out how to hide a menu item however. The menu item I want to hide from displaying in the global navigation is my "Site Map" page. Now I know that there is something called a VisibilityProvider available to me on the mvcSiteMapNode - but I can't seem to figure out how to make it work.

推荐答案

首先,我建议您阅读以下Wiki页面:

First, I suggest you read this wiki page: Creating a Custom SiteMapNodeVisibilityProvider. Then for the specific node that points to your Site Map page, declare it this way:

<mvcSiteMapNode title="Site Map" controller="Home" action="Map" visibility="false" />

现在,在实现IsVisible方法(如上面链接的Wiki页面所示)时,您可以执行以下操作:

Now, when implementing the IsVisible method (shown in the wiki page linked above), you can do this:

string visibility = mvcNode["visibility"];

// Is a visibility attribute specified?
if (!string.IsNullOrEmpty(visibility))
{
     isVisible = Convert.ToBoolean(mvcNode["visibility"]);

     if (!isVisible)
     {
          return false;
     }
}

return true;

这篇关于ASP.NET MVC SiteMap提供程序-如何在实际菜单中“隐藏"单个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆