gpt4 book ai didi

c# - MVC SiteMap 从 menuhelper 中隐藏一个节点,但在 sitepathhelper 中显示(面包屑)

转载 作者:太空狗 更新时间:2023-10-30 00:53:46 25 4
gpt4 key购买 nike

我试图从我的站点菜单中隐藏一个节点,但在我的面包屑中显示它

我正在按照此处的教程进行操作:https://github.com/maartenba/MvcSiteMapProvider/wiki/Advanced-Node-Visibility

<mvcSiteMapNode title="Create Customer" controller="Customer" action="Create" area="Home" clickable="false" visibility="SiteMapPathHelper,!*"/>  

以上似乎不起作用。它同时出现在我的网站菜单和面包屑中。

最佳答案

我们创建了一个 OnlyBreadCrumbMVCSiteMapNodeAttribute。我们装饰我们想要属性的任何代码

public class OnlyBreadCrumbMvcSiteMapNodeAttribute : MvcSiteMapNodeAttribute
{
public OnlyBreadCrumbMvcSiteMapNodeAttribute(string title, string parentKey)
{
Title = title;
ParentKey = parentKey;
VisibilityProvider = typeof(BreadCrumbOnlyVisibilityProvider).AssemblyQualifiedName;
}
public OnlyBreadCrumbMvcSiteMapNodeAttribute(string title, string parentKey, string key)
{
Title = title;
Key = key;
ParentKey = parentKey;
VisibilityProvider = typeof(BreadCrumbOnlyVisibilityProvider).AssemblyQualifiedName;
}
}

还有一个可见性提供者

public class BreadCrumbOnlyVisibilityProvider : ISiteMapNodeVisibilityProvider
{
public bool IsVisible(SiteMapNode node, HttpContext context, IDictionary<string, object> sourceMetadata)
{
if (sourceMetadata["HtmlHelper"] == null || (string)sourceMetadata["HtmlHelper"] == "MvcSiteMapProvider.Web.Html.SiteMapPathHelper")
{
return true;
}
return false;
}
}

像这样使用

    [OnlyBreadCrumbMvcSiteMapNode("Upload Documents", "AssetDocuments")]
public virtual ActionResult FileUpload(int assetId)

上传文档将成为面包屑标题。 AssetDocuments 是父键

如果传递第三个参数,则设置面包屑节点本身的键

关于c# - MVC SiteMap 从 menuhelper 中隐藏一个节点,但在 sitepathhelper 中显示(面包屑),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15186307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com