1

I have a mvc.SiteMap defined something like this:

<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0"
        xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0    MvcSiteMapSchema.xsd"
        enableLocalization="true" >

<mvcSiteMapNode title="Home" controller="Home" action="Index" key ="_Home_">
    <mvcSiteMapNode title="View Plans" controller="Home" action="ViewCompletePlans"/>
        <mvcSiteMapNode title="Edit Plan" controller="Plan" action="EditPlan" dynamicNodeProvider= {pathToProvider}>
            <mvcSiteMapNode title="Critical Functions" controller="Plan" action="EditCriticalandNormalFunctions" dynamicNodeProvider={pathToProvider}>
                <mvcSiteMapNode title="Edit Critical Function" controller="CriticalFunction" action="EditCriticalFunction" dynamicNodeProvider= {pathToProvider}>
                    <mvcSiteMapNode title="Manage Uploaded Documents" controller="CriticalFunction" action="UploadedDocuments" dynamicNodeProvider={pathToProvider}></mvcSiteMapNode>
                </mvcSiteMapNode>
            </mvcSiteMapNode>
        </mvcSiteMapNode>
    </mvcSiteMapNode>
</mvcSiteMap>  

At each level, the nodes are generated dynamically from values in a database. My problem is that for child nodes, the node provider is called multiple times when building the site map. I am not sure if it is:

  1. Called once for each of the parent type created. So if there are 5 plans, then the provider for critical functions is called 5 times, so the nodes are generated 5 times. If so, is there some way to pass the provider information so I can only generate the nodes associated with the current parent node, not all nodes with that type? Or is there a way to access the current parent node?
  2. Being called more than once for another reason, although the highest level dynamic node provider is only being called once.

The code works right now, but it is very inefficient.

Here is a sample provider:

public class CriticalFunctionNodeProvider : DynamicNodeProviderBase  
{  
      public override IEnumerable<DynamicNode> GetDynamicNodeCollection()  
    {
        var db = new COPEntities();
        var returnValue = new List<DynamicNode>();
        foreach (var criticalFunction in db.NormalFunctions)
        {
            var node = new DynamicNode();
            node.Title = "Critical Function: " + criticalFunction.FunctionName;
            node.ParentKey = "_Plan_" + criticalFunction.PlanId + "_CritFuncs_";
            node.RouteValues.Add("planId", criticalFunction.PlanId);
            node.RouteValues.Add("id", criticalFunction.Id);
            node.Key = "_Plan_" + criticalFunction.PlanId + "_CritFuncs_" + criticalFunction.Id;
            returnValue.Add(node);
        }
        return returnValue;
    }
}  

Any help is greatly appreciated.

4

1 に答える 1

0

Currently there is no way to do this, except to make the hierarchy in single DynamicNodeProvider. But it would be a great addition.

于 2012-04-12T18:01:11.633 に答える