NewsGrrl115DE4
New Member
I'm trying to generate a navigation menu out of a sitemap-xml-file.I'm using a Recursive-Razor-Helper-Function and call the code froma cshtml-side. For some reason the the 2 sub-items on the secondnode get duplicated, and I don't get it, why. I someone can help,or fix this.Sitemap-XML:\[code\]<siteMap> <siteMapNode url="~/" title="001"/> <siteMapNode url="#" title="002"> <siteMapNode url="~/Url01" title="002_01"/> <siteMapNode url="~/Url02" title="002_02"/> </siteMapNode></siteMap>\[/code\]Code from the _Layout.cshtml:\[code\] @helper xMenu(System.Xml.XmlNodeList nodes) { <ul> @foreach (System.Xml.XmlNode node in nodes) { string ntitle = node.Attributes["title"].Value; string nurl = node.Attributes["url"].Value; <li><a href="http://stackoverflow.com/questions/15566899/@nurl">@ntitle</a> @if (node.HasChildNodes) { @xMenu(node.ChildNodes) } </li> } </ul> } @{ System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument(); xmldoc.Load(Server.MapPath("~/Sitemap.xml")); System.Xml.XmlNodeList settings = xmldoc.SelectNodes("/siteMap"); System.Xml.XmlNodeList nodes = xmldoc.GetElementsByTagName("siteMapNode"); ViewBag.MyMenu = nodes; } @xMenu(ViewBag.MyMenu)\[/code\]