Controller name from Parent Node

Apr 20, 2009 at 11:04 PM
Hi,

thanks for the project, great work!

I needed take controller from parent node because of more simple syntax. I changed some code and if think it's helpful, use it.

Again, thanks for provider :).

Martin

Example:

<mvcSiteMapNode title ="Code Lists" controller="CodeList" action="Index">
        <mvcSiteMapNode title="Type One" controller="CodeListType_1">          
          <mvcSiteMapNode title="Vytvoř" action="Create" isDynamic="true" dynamicParameters="id"/>
          <mvcSiteMapNode title="Detail" action="Details" isDynamic="true" dynamicParameters="id"/>
          <mvcSiteMapNode title="Editace" action="Edit" isDynamic="true" dynamicParameters="id"/>
          <mvcSiteMapNode title="Smazání" action="Delete" isDynamic="true" dynamicParameters="id"/>
        </mvcSiteMapNode>

        <mvcSiteMapNode title="Type Two" controller="CodeListType_2">          
          <mvcSiteMapNode title="Vytvoř" action="Create" isDynamic="true" dynamicParameters="id"/>
          <mvcSiteMapNode title="Detail" action="Details" isDynamic="true" dynamicParameters="id"/>
          <mvcSiteMapNode title="Editace" action="Edit" isDynamic="true" dynamicParameters="id"/>
          <mvcSiteMapNode title="Smazání" action="Delete" isDynamic="true" dynamicParameters="id"/>
        </mvcSiteMapNode>

        <mvcSiteMapNode title="Type Three" controller="CodeListType_3">          
          <mvcSiteMapNode title="Vytvoř" action="Create" isDynamic="true" dynamicParameters="id"/>
          <mvcSiteMapNode title="Detail" action="Details" isDynamic="true" dynamicParameters="id"/>
          <mvcSiteMapNode title="Editace" action="Edit" isDynamic="true" dynamicParameters="id"/>
          <mvcSiteMapNode title="Smazání" action="Delete" isDynamic="true" dynamicParameters="id"/>
        </mvcSiteMapNode>

... and more and more...

</mvcSiteMapNode>




So I changed the function GetMvcSiteMapNodeFromXMLElement in file MvcSiteMapProvider.cs.


 protected SiteMapNode GetMvcSiteMapNodeFromXMLElement(SiteMapNode parentNode, XElement node)
        {
            // Is the node to be handled by the current provider?
            var provider = GetAttributeValue(node.Attribute("provider"));
            if (!string.IsNullOrEmpty(provider))
                return GetSiteMapNodesFromProvider(provider);

            //Check Controller Name and try get parent
            if (node.Attribute("controller") == null && (parentNode is MvcSiteMapNode))
            {
                string parentControllerName = (parentNode as MvcSiteMapNode).Controller;
                if (!string.IsNullOrEmpty(parentControllerName))
                    node.SetAttributeValue("controller", parentControllerName);
            } 



.......






Apr 21, 2009 at 10:07 AM
Great suggestion! Will create a work item for that.
Apr 21, 2009 at 10:13 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.