MVCSiteMapProvider忽略参数

时间:2016-05-26 09:28:17

标签: asp.net mvcsitemapprovider

我正在使用MVCSiteMapProvider.MVC5,我正在尝试设置我的站点地图。

我的路线是:

通知/

通知/警报/

通知/警告/

通知/信息/

警报,警告和信息将传递给“notificationFilter”操作参数。

这是我的基本网站地图,目前通过面包屑显示路线通知/主页>通知。

  <mvcSiteMapNode title="Home" controller="Dashboard" action="System">
     <mvcSiteMapNode title="Vacuum Management" controller="Dashboard" action="SubSystem" />
     <mvcSiteMapNode title="Notifications" controller="Notifications" action="SystemNotifications" />
 </mvcSiteMapNode>

我想要做的是添加一个catch all,这样如果传递了“notificationFilter”参数(例如notification / Alarm /),它仍然会将痕迹显示为Home&gt; Notifications并忽略该参数。

我试过这个:

  <mvcSiteMapNode title="Home" controller="Dashboard" action="System">
     <mvcSiteMapNode title="Vacuum Management" controller="Dashboard" action="SubSystem" />
     <mvcSiteMapNode title="Notifications" controller="Notifications" action="SystemNotifications" notificationFilter="Alarm" />

适用于通知/警报,但没有其他功能。我也试过添加多行:

  <mvcSiteMapNode title="Home" controller="Dashboard" action="System">
     <mvcSiteMapNode title="Vacuum Management" controller="Dashboard" action="SubSystem" />
     <mvcSiteMapNode title="Notifications" controller="Notifications" action="SystemNotifications" notificationFilter="Alarm" />
     <mvcSiteMapNode title="Notifications" controller="Notifications" action="SystemNotifications" notificationFilter="Warning" />
     <mvcSiteMapNode title="Notifications" controller="Notifications" action="SystemNotifications" notificationFilter="Information" />

但是因为标题是关键所以面包屑会显示不同的文字。

所有帮助表示赞赏。

提前致谢!

路线配置:

            routes.MapRoute(
            name: "NotificationsSystem",
            url: "notifications",
            defaults: new { controller = "Notifications", action = "SystemNotifications", notificationFilter = "" }
            );

        routes.MapRoute(
            name: "NotificationsSystemFiltered",
            url: "notifications/{notificationFilter}",
            defaults: new { controller = "Notifications", action = "SystemNotifications", notificationFilter = "" }
            );

1 个答案:

答案 0 :(得分:1)

根据the documentation,可以使用preservedRouteParameters来获取单个节点以匹配特定参数的任何值。

<mvcSiteMapNode title="Notifications" controller="Notifications" action="SystemNotifications" preservedRouteParameters="notificationFilter" />

当您的节点没有子节点时,这很有效,但如果您将此属性放在有子节点的节点上,则需要take into consideration what will happen when the user navigates back up the hierarchy