这是我的数据库表
如何生成站点地图?
控制器是类别
动作是 Id
就是这样
TreeMenu.cs:
using System;
using System.Collections.Generic;
namespace Pmvc.Models
{
public partial class TreeMenu
{
public int TreeId { get; set; }
public int TreeParentId { get; set; }
public string TreeName { get; set; }
public List<TreeMenu> Children { get; set; }
}
}
StoreDetailsDynamicNodeProvider.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcSiteMapProvider.Extensibility;
using Pmvc.Models;
namespace Pmvc
{
public class StoreDetailsDynamicNodeProvider : DynamicNodeProviderBase
{
PMVCEntities pmvcDB = new PMVCEntities();
public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
{
var nodes = new List<DynamicNode>();
foreach (var treemenu in pmvcDB.TreeMenu)
{
nodes.Add(CreateNode(treemenu));
}
return nodes;
}
private DynamicNode CreateNode(TreeMenu treemenu)
{
DynamicNode node = new DynamicNode();
node.Action = "ProductDetails";
node.Controller = "Product";
node.Title = treemenu.TreeName;
if (treemenu.Children != null)
{
foreach (var child in treemenu.Children)
{
node.Children.Add(CreateNode(child)); //This line is wrong!
}
}
return node;
}
}
}
错误的:
'MvcSiteMapProvider.Extensibility.DynamicNode' 不包含 'Children' 定义,并且找不到扩展方法 'Children'
public class StoreDetailsDynamicNodeProvider : DynamicNodeProviderBase
{
PMVCEntities pmvcDB = new PMVCEntities();
public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
{
// Build value
var returnValue = new List<DynamicNode>();
// Create a node for each album
foreach (var treemenu in pmvcDB.TreeMenu)
{
DynamicNode node = new DynamicNode();
node.Action = "ProductDetails";
node.Controller = "Product";
node.Title = treemenu.TreeName;
node.RouteValues.Add("id", treemenu.TreeId);
returnValue.Add(node);
}
// Return
return returnValue;
}
}
这是我的桌子
TreeId TreeParentId 树名
1 0 类别 1
2 1 菜单项 X
3 1 菜单项 Y
4 1 菜单项 Z
5 0 类别 2
6 5 其他菜单 1
7 5 其他菜单 2
8 0 空类别
9 7 菜单 Lvl 3
如何编写子节点代码?