public override IEnumerable <DynamicNode> GetDynamicNodeCollection(ISiteMapNode node) { using (var db = new ApplicationDbContext()) { foreach (Category c in db.Category) { DynamicNode n = new DynamicNode(); n.Title = c.CategoryTitle; n.Key = "Kategoria_" + c.CategoryID; // Optional: Add the parent key // (and put a key="Home" on the node that you want these nodes children of) //n.ParentKey = "Home"; // Add your route values // Route Option 1 n.RouteValues("id", c.CategoryID); // Route Option 2 // n.RouteValues("CategoryID", c.CategoryID); // Optional: Add any route values to match regardless of value // n.PreservedRouteParameters.Add("myKey"); yield return(n); } } }
public override IEnumerable <DynamicNode> GetDynamicNodeCollection(ISiteMapNode node) { using (var db = new ApplicationDbContext()) { foreach (Product p in db.Product) { DynamicNode n = new DynamicNode(); n.Title = p.ProductTitle; n.Key = "Product_" + p.ProductID; // IMPORTANT: Setup the relationship with the // parent node (category) by using the foreign key in // your database. ParentKey must exactly match the Key // of the node this node is to be a child of. // If this is a many-to-many relationship, you will need // to join to the table that resolves the relationship above // and use the right key here. n.ParentKey = "Kategoria_" + p.CategoryID; // Add your route values // Route Option 1 n.RouteValues("id", p.ProductID); // Route Option 2 // n.RouteValues("ProductID", p.ProductID); // Optional: Add any route values to match regardless of value // n.PreservedRouteParameters.Add("myKey"); yield return(n); } } }