且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在NopCommerce 3.8的管理面板中添加子菜单

更新时间:2023-11-29 23:17:10

您的代码需要一些修复:

Your code need some fixes:

  1. menuItem是父节点,不需要RouteValues.
  2. 基本上,父节点需要SystemName
  1. menuItem is a parent node, does not required RouteValues.
  2. Basically, parent node needs SystemName

进行较大更改后,父节点应如下所示:

After doing upper changes, the parent node should be look like:

var menuItem = new SiteMapNode
{
    Title = "Promo Slider",
    Visible = true,
    SystemName = "Widgets.PromoSlider",
};


好吧,现在进入子节点,您每次都在创建一个新节点.而不是添加到父节点!


Okay, now coming to the child nodes, you're creating new node each time..instead of add to the parent one!

var createUpdate = new SiteMapNode()
var manageSlider = new SiteMapNode()

因此,将其更改为:

menuItem.ChildNodes.Add(new SiteMapNode
{
    SystemName = "Widgets.PromoSlider",
    Title = "New Sliders",
    ControllerName = "PromoSlider",
    ActionName = "CreateUpdatePromoSlider",
    Visible = true,
    RouteValues = new RouteValueDictionary() { { "area", null } }
});

menuItem.ChildNodes.Add(new SiteMapNode
{
    SystemName = "Widgets.PromoSlider",
    Title = "Manage Sliders",
    ControllerName = "PromoSlider",
    ActionName = "ManagePromoSliders",
    Visible = true,
    RouteValues = new RouteValueDictionary() { { "area", null } }
});

最后,将父节点添加到插件"节点:

At the end, add parent node to the Plugins node:

var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Third party plugins");
if (pluginNode != null)
    pluginNode.ChildNodes.Add(menuItem);
else
    rootNode.ChildNodes.Add(menuItem); 

全部完成!运行它,它将根据需要显示.

All done! Run it and it will display as you want.