Multiple Navigation Paths to a Single Page

情到浓时终转凉″ 提交于 2019-12-11 09:57:45

问题


I'm trying to use the Multiple Navigation Paths to a Single Page feature from the MvcSiteMapProvider: https://github.com/maartenba/MvcSiteMapProvider/wiki/Multiple-Navigation-Paths-to-a-Single-Page

And these are the 2 different navigation path that's pointing to the same resource:

<mvcSiteMapNode title="Multi Analysis" controller="Report" action="MultiAnalysis" preservedRouteParameters="id">
<mvcSiteMapNode title="Analysis" controller="Report" action="Analysis" preservedRouteParameters="id,type" type="ma" />
</mvcSiteMapNode>

<mvcSiteMapNode title="Single Analysis" controller="Report" action="SingleAnalysis" preservedRouteParameters="id">
<mvcSiteMapNode title="Analysis" controller="Report" action="Analysis" preservedRouteParameters="id,type" type="sa" />
</mvcSiteMapNode>

But, the breadcrumb is always generated for the top one. Is there something that I'm missing?


回答1:


Yes, there is something you are missing. A route value and preserved route value cannot be used simultaneously for the same node. I have updated the wiki page because the example configuration was also invalid.

<mvcSiteMapNode title="Multi Analysis" controller="Report" action="MultiAnalysis" preservedRouteParameters="id">
    <mvcSiteMapNode title="Analysis" controller="Report" action="Analysis" preservedRouteParameters="id" type="ma" />
</mvcSiteMapNode>

<mvcSiteMapNode title="Single Analysis" controller="Report" action="SingleAnalysis" preservedRouteParameters="id">
    <mvcSiteMapNode title="Analysis" controller="Report" action="Analysis" preservedRouteParameters="id" type="sa" />
</mvcSiteMapNode>

Note the lack of "type" in the preservedRouteParameters in this case.

Using preservedRouteParameters is for forcing all possible Ids to match a single node by copying the parameter from the current request. This is generally only useful for making the SiteMapPath HTML helper work alongside CRUD operations where you are using a list or table of database records as your main navigation. If you are using the Menu or SiteMap HTML helpers or you want the pages listed in the /sitemap.xml endpoint (the sitemaps XML for search engines), using preservedRouteParameters is not recommended.

I have created a working demo of this feature on my blog: http://www.shiningtreasures.com/post/2013/08/10/mvcsitemapprovider-4-seo-features#canonical-tag




回答2:


This worked for now:

MvcSiteMapProvider.SiteMaps.GetSiteMap().Clear(); MvcSiteMapProvider.SiteMaps.GetSiteMap().BuildSiteMap();

I guess I'll continue using this until I figure out how the caching works on MvcSiteMapProvider



来源:https://stackoverflow.com/questions/18498521/multiple-navigation-paths-to-a-single-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!