maartenba / MvcSiteMapProvider

An ASP.NET MVC SiteMapProvider implementation for the ASP.NET MVC framework.
Microsoft Public License
539 stars 218 forks source link

Multiple nodes to point to the same action but with diferents url parameters #372

Closed gregorypilar closed 9 years ago

gregorypilar commented 10 years ago

HI,

I have a four dynamic nodes that point to the same controller and action , I generated the nodes lik this :

  foreach (var canal in canales)
            {
                var myNode = new DynamicNode
                {
                    Title = canal.Nombre,
                    Description = canal.Nombre,
                    Controller = "PeriodoCorte",
                    Action = "CortesPorCanal",
                    ParentKey ="a939d77a-bfea-49a5-898a-2aa50f9b7f99",
                    Key = Guid.NewGuid().ToString(),
                    CanonicalKey = "a939d77a-bfea-49a5-898a-2aa50f9b7f99",
                    Roles = new List<string>()
                };
                myNode.Roles.Add(canal.CodigoCanal);

                //
                myNode.RouteValues.Add("canalId", canal.Id);
                myNode.RouteValues.Add("corteId", canal.CorteActual.Id);
                //
                returnValue.Add(myNode);
            }

The only difference on the nodes are the routevalues , and the problem that Im facing is , when I click a node always the value the current node is equal to the first node that is generated , no the node that I clicked

there is a way using SiteMaps.Current o something that I can get the right node

NightOwl888 commented 10 years ago

The behavior you describe sounds like it may be a bug if your nodes are configured right and all have unique canalId and corteId combinations.

Since dynamic nodes are declared as a definition node and the definition node values are the defaults of your dynamic nodes, you could have extra route values or custom attributes that you didn't intend to make route values if you haven't explicitly ignored them. I suspect that is what is happening here, but the best way to check is to ensure your URLs are being generated correctly with no extra querystring paramters.

<mvcSiteMapNode title="Dynamic Nodes" customValue="foo" dynamicNodeProvider="MyNamespace.DynamicNodeProvider, MyAssembly"/>

To ignore them, you should add them to the AttributesToIgnore setting.

<add key="MvcSiteMapProvider_AttributesToIgnore" value="customValue,someOtherCustomValue"/>

If that doesn't work, I would appreciate if you could set up a small sample project with the same behavior and post it on GitHub or make it available for download.

gregorypilar commented 10 years ago

I have to force it using this this.GetCurrentSiteMapNodeForChildAction().Title , and using the parameters adding a round trip to find the name I will make a test project with the same behavior so it could tested

NightOwl888 commented 9 years ago

Since you haven't provided a way to duplicate this issue, I am closing it for now. Feel free to reopen it if you are still seeing this behavior and can provide more info.