MVC SiteMap 2.0 支持自定义属性吗?

发布于 2024-09-11 16:37:58 字数 564 浏览 3 评论 0原文

我正在使用 MVC SiteMap 项目的 v2.0。

使用 Web 表单中的 System.Web.XmlSiteMapProvider,我经常在节点上存储自定义属性,并通过 Attributes[] 集合访问它们。这对于构建非标准节点集合非常有用,所有节点都共享一个属性。

MVC SiteMap 似乎不支持自定义属性。这是对的吗?如果没有,任何人都可以建议一种识别站点地图中应被视为“主要”导航的节点的好方法吗?


编辑:

我应该澄清属性如何显得“不起作用”。当我向根节点添加自定义属性(例如 isPrimary="true")时,我的 SiteMap.CurrentNode 属性始终为 null。但是,SiteMap.RootNode 属性填充得很好。有什么想法吗?


进一步编辑:

鉴于我添加的任何其他属性都将添加到 RouteData,是否有一种方法可以将属性添加到与路线没有任何关系的节点?我正在考虑一个可以用来识别某些节点的任意参数。

I'm using v2.0 of the MVC SiteMap project.

With the System.Web.XmlSiteMapProvider in webforms, I often stored custom attributes on nodes, and accessed them through the Attributes[] collection. This is very useful for building non-standard collections of nodes, that all share an attribute.

The MVC SiteMap doesn't seem to support custom attributes. Is this right? If not, can anyone suggest a good way of identifying the nodes in my SiteMap that should be considered the "primary" navigation?


Edit:

I should clarify how attributes appear to "not work". When I add a custom attribute, e.g isPrimary="true" to my root node, my SiteMap.CurrentNode property is always null. However, the SiteMap.RootNode property is populated fine. Any ideas?


Further Edit:

Given that any additional attributes I add will added to RouteData, is there a way of adding an attribute to a node that isn't related in any way to the route? I'm thinking of an arbitrary parameter that I can use to identify certain nodes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尐偏执 2024-09-18 16:37:58

这在最新版本的提供程序中工作得很好。刚刚使用最新的源代码和 MVC 音乐站点演示对此进行了测试。

很确定这总是有效的。 AddNode() 方法都调用 base.AddNode 方法,该方法将添加您想要的任何属性。

更新:

尝试了你的例子,工作正常。当我测试这个时,我实际上在 SiteMap.Provider.CurrentNode 上进行了调试,并且自定义属性就在那里。也许这是一个错误,尝试最新的下降?

This works just fine in the latest version of the provider. Just tested this using the latest source code and MVC Music Site Demo.

Pretty sure this always worked. The AddNode() methods all call the base.AddNode methods which will add whatever attributes you'd like.

Update:

Tried your example, works fine. When I tested this I actually debugged on the SiteMap.Provider.CurrentNode and the custom attributes were there. Maybe its a bug, try the latest drop?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文