在NopCommerce 3.8的管理面板中添加子菜单 [英] Add Submenu in admin panel in NopCommerce 3.8

查看:273
本文介绍了在NopCommerce 3.8的管理面板中添加子菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Pluralsight提供的教程中学习Nopcommerce.

I am learning Nopcommerce from the tutorial provided by Pluralsight.

在管理面板中添加插件菜单时,与3.5和3.8版本不同.没有public SiteMapNode BuildMenuItem() 相反,我们必须使用public void ManageSiteMap(SiteMapNode rootNode).

When it comes to adding menu for the plugin in the admin panel it is different with the version 3.5 and 3.8. There is no public SiteMapNode BuildMenuItem() instead we have to use public void ManageSiteMap(SiteMapNode rootNode).

我已根据NopCommerce提供的文档使用ManageSiteMap

I have used ManageSiteMap according to the documentation provided by NopCommerce How to add a menu item into the administration area from a plugin, but by using that code i was only able to show the parent menu not the sub menu.

这是我的代码:

public void ManageSiteMap(SiteMapNode rootNode)
{
      var menuItem = new SiteMapNode()
      {
          Title = "Promo Slider",
          ControllerName = "PromoSlider",
          ActionName = "CreateUpdatePromoSlider",
          Visible = true,
          RouteValues = new RouteValueDictionary() { { "area", "admin" } }
      };
      var createUpdate = new SiteMapNode()
      {
          SystemName = "Widgets.PromoSlider",
          Title = "New Sliders",
          ControllerName = "PromoSlider",
          ActionName = "CreateUpdatePromoSlider",
          Visible = true,
         RouteValues = new RouteValueDictionary() { { "area", null } }
      };

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

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

但是它显示的只是父菜单

But all it shows is the parent menu only

我想这样显示

插件
    | ----> Promo Slider
      | ----------->新滑块
      | ------------->管理滑块

Plugins
    |---->Promo Slider
      |-----------> New Slider
      |-----------> Manage Sliders

任何人都可以帮我提供我的代码.

Can anyone please help me with my code.

推荐答案

您的代码需要一些修复:

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.

这篇关于在NopCommerce 3.8的管理面板中添加子菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆