confused on dynamically adding nodes

May 15, 2010 at 1:41 PM

I am trying to add to a set of nodes as follows:

 // assign reference to the child nodes
SiteMapNodeCollection childNodes = SiteMap.CurrentNode.ParentNode.ChildNodes;            

// clear any exissting nodes

// add a couple of new nodes
childNodes.Add(new SiteMapNode(SiteMap.Provider, "", "#?abc", "test1")); 
childNodes.Add(new SiteMapNode(SiteMap.Provider, "", "#?xyz", "test2")); 

// Reassign back to the original child node collection
SiteMap.CurrentNode.ParentNode.ChildNodes = childNodes;

Debugging reveals that SiteMap.CurrentNode.ParentNode now has the 2 nodes that were added, and correctly does not have the node that was originally there. However, nothing displays on the page / html. It as though the code above was "reset" or something.

If I do not clear the child collection - the screen shows the original link / node, but not the other 2 - even when debugging reveals that they exists in the child node collection.

Any assistance here much appreciated.



May 16, 2010 at 1:04 AM

Here's the relavant portion on the sitemap.xml:

 <mvcSiteMapNode title="Application Forum" controller="ApplicationForum"
          Key="ApplicationForum" visibility="InSiteMapPathOnly" >
                             <!-- This node displays as expected. Dynamically clearing node collection will correctly prevent display.-->
                            <mvcSiteMapNode title="Refresh" action="Forum"  isDynamic="true" dynamicParameters="id" />

All i am trying to do is add additonal nodes to this. The existing node (Refresh) will always display so i know this is defined okay. As mentioned though, any additional nodes are disregarded in the display.

To note that the action I am coding in is the actual page/view represented by the Refresh node. Is it because i am "in" the page that isthe current node that I have left it too late to dynamically add nodes??


Jun 9, 2010 at 6:51 AM

ok - so seem thsi question goes unanswered all over this forum. Very annoying as all I need to know is if it is possibel or not...

To note that my nodes are indeed added to teh collection, but they are not appearing alongside teh statically defined nodes (output using Html.MenuPinned).

Anyone at all able to answer this or provide even teh slightest cluse a t what is going wrong??


Jun 9, 2010 at 11:23 AM

Hello Andy,

Sorry for being unresponsive. This will not be fixed in the current version of the provider. However, yesterday a CTP of a new version was released (check the downloads tab). This does not contain any of the HtmlHelper methods, but it does contain a rewritten engine for adding and removing nodes. Check the example in the download, which will probably contain the info you need.

Best regards,