0

following is my sitemap code :

<mvcSiteMapNode title="Partner" controller="Partner" key="Partner" action="ShowPartners" >
  <mvcSiteMapNode title="ISP" controller="ISP" key="ISP"  action="ShowPartnersIsps" preservedRouteParameters="Id" >
    <mvcSiteMapNode title="Operator" controller="Operator" key="Operator"  action="ShowIspsOperators" preservedRouteParameters="Id" >
      <mvcSiteMapNode title="Subscriber" controller="Subscriber" key="Subscriber"  action="ShowOperatorsSubscribers" preservedRouteParameters="Id" >
        <mvcSiteMapNode title="Router" controller="Router" key="Router"  action="ShowSubscribersRouters" preservedRouteParameters="Id" />
      </mvcSiteMapNode>
    </mvcSiteMapNode>
  </mvcSiteMapNode>
</mvcSiteMapNode>

following is my route.config

        routes.MapRoute(
            "GetPartnerRoute",
            "Partner/ShowPartners/{search}",
            new { controller = "Partner", action = "ShowPartners", Search = UrlParameter.Optional }
        );

        routes.MapRoute(
          "GetISPRoute",
             "ISP/ShowPartnersIsps/{Id}/{Search}",
            new { controller = "ISP", action = "ShowPartnersIsps", Id = UrlParameter.Optional, Search = UrlParameter.Optional }
        );

        routes.MapRoute(
            "GetOperatorRoute",
            "Operator/ShowIspsOperators/{Id}/{Search}",
            new { controller = "Operator", action = "ShowIspsOperators", Id = UrlParameter.Optional, Search = UrlParameter.Optional }
        );

        routes.MapRoute(
            "GetSubscriberRoute",
            "Subscriber/ShowOperatorsSubscribers/{Id}/{Search}",
            new { controller = "Subscriber", action = "ShowOperatorsSubscribers", Id = UrlParameter.Optional, Search = UrlParameter.Optional }
        );

        routes.MapRoute(
            "GetRouterRoute",
            "Router/ShowSubscribersRouters/{Id}/{Search}",
            new { controller = "Router", action = "ShowSubscribersRouters", Id = UrlParameter.Optional, Search = UrlParameter.Optional }
        );

the id parameters is not same for all node.

in above situation.

each node has different "Id" value. which not similar for every node. by renaming "Id" i can achieve what i expected. but i cant change the name of "Id". so when i goes to child node which having parameter "Id" it sets similar value to its parent node.

following is my code after inspect :

Home >

    <a href="/Partner/ShowPartners" title="Partner">Partner</a>
     &gt; 

    <a href="/ISP/ShowPartnersIsps/268e4984-0923-4db7-8dd3-78564663e4d1" title="ISP">ISP</a>
     &gt; 

    <a href="/Operator/ShowIspsOperators/268e4984-0923-4db7-8dd3-78564663e4d1" title="Operator">Operator</a>
     &gt; 

    <a href="/Subscriber/ShowOperatorsSubscribers/268e4984-0923-4db7-8dd3-78564663e4d1" title="Subscriber">Subscriber</a>
     &gt; 

"268e4984-0923-4db7-8dd3-78564663e4d1" is similar for every node. which should be different.

how can i achieve this. please help

NightOwl888
  • 55,572
  • 24
  • 139
  • 212

1 Answers1

0

When using preservedRouteParameters, the values are "preserved" from the current request. By definition that means a route value can only be used for a singular purpose (although that purpose can span multiple nodes).

There are 2 ways to overcome this:

  1. Use a different route key for each purpose ({ispId}, {operatorId}, etc).
  2. Instead of using preservedRouteParameters, use the default behavior of MvcSitemapProviderwhich expects a unique node perid`. You can build up the parent-child relationships by using a dynamic node provider.

The first option is more scalable. The second option gives you more control (but only scales to about 10,000 nodes).

Do note that for preservedRouteParameters to work right, you need to put all of the ancestor's route values into the current request. So, for example you must provide ispId for the Operator node. Even though your action method may not require it, the parent node ISP still does for it to build the URL correctly.

See demos of both of these options here: https://github.com/NightOwl888/MvcSiteMapProvider-Remember-User-Position

NightOwl888
  • 55,572
  • 24
  • 139
  • 212