Add Submenu in admin panel in NopCommerce 3.8

做~自己de王妃 提交于 2019-12-12 16:00:40

问题


I am learning Nopcommerce from the tutorial provided by Pluralsight.

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).

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.

This is my code:

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

I want to show like this

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

Can anyone please help me with my code.


回答1:


Your code need some fixes:

  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()

So, change it to:

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.



来源:https://stackoverflow.com/questions/41510580/add-submenu-in-admin-panel-in-nopcommerce-3-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!