gpt4 book ai didi

asp.net-mvc - MVCSiteMapProvider - 显示父节点的标题

转载 作者:行者123 更新时间:2023-12-04 02:09:38 26 4
gpt4 key购买 nike

我希望能够显示当前节点的父节点的标题。

站点地图:

    <mvcSiteMapNode title="Main Site Tile" controller="Home" action="Index">
<mvcSiteMapNode title="Some site section" controller="Section" action="Index">
<mvcSiteMapNode title="Some page" controller="Section" action="Page1" />
<mvcSiteMapNode title="Some other page" controller="Section" action="Page2" />
</mvcSiteMapNode>
</mvcSiteMapNode>

因此,在“第 1 页”上,我可以使用以下方法显示标题(某页):

Html.MvcSiteMap().SiteMapTitle()

太棒了。但是,我还想在我的 _Layout 页面中显示父节点(某些站点部分)的标题,因此如果我正在查看“Page1”或“Page2”(或者实际上嵌套在其中的任何 View ),这将看起来相同。

这可能吗?

最佳答案

您可以使用 SiteMapTitle 属性并将 Target 设置为 ParentNode 来执行此操作。

[MvcSiteMapProvider.Web.Mvc.Filters.SiteMapTitle("SomeKey", Target = AttributeTarget.ParentNode]
public ViewResult Show(int blogId) {
ViewData["SomeKey"] = "This will be the title";

var blog = _repository.Find(blogId);
return View(blog);
}

这将设置菜单和 SiteMapPath 中链接的标题。

您还可以使用静态 SiteMaps 对象以编程方式访问节点。

var theTitle = MvcSiteMapProvider.SiteMaps.Current.CurrentNode.ParentNode.Title;

或者,您可以使用 FindSiteMapNodeFromKey("theKey") 方法在 SiteMap 中查找任何节点以获取其标题。

关于asp.net-mvc - MVCSiteMapProvider - 显示父节点的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19772060/

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