繁体   English   中英

nopcommerce尝试在管理面板中添加自定义标签

[英]nopcommerce trying to add custom tab in admin panel

好的,对于类别编辑页面,我已经在nopcommerce管理面板中添加了一个自定义标签,因此我试图对制造商编辑页面进行相同的操作,但是未显示该标签的内容。

管理员图片

这是我正在使用的代码:

using System.Web.Mvc;
using System.Web.Routing;
using Nop.Services.Events;
using Nop.Web.Framework.Events;

namespace Nop.Plugin.Widgets.Modifications.Events
{
/// <summary>
/// This class is used to detect when a Manufacturer is being edited in order to add a new tab for attachments.
/// </summary>
public class ManufacturerTabConsumer : IConsumer<AdminTabStripCreated>
{
    public void HandleEvent(AdminTabStripCreated eventMessage)
    {
        if (eventMessage.TabStripName == "manufacturer-edit")
        {
            //Manufacturer Attachments tab
            var manufacturerId = eventMessage.Helper.ViewContext.RequestContext.RouteData.Values["Id"];

            var urlHelper = new UrlHelper(eventMessage.Helper.ViewContext.RequestContext)
                .RouteUrl("Nop.Plugin.Widgets.Modifications.Admin.ManufacturerAttachments",
                    new RouteValueDictionary { { "manufacturerId", manufacturerId } });

            eventMessage.BlocksToRender.Add(new MvcHtmlString("<script>" +
                                                              "$(document).ready(function() {" +
                                                              "var tabStrip = $('#manufacturer-edit').data('kendoTabStrip').append({" +
                                                              "text: 'Attachments'," +
                                                              "animation: { open: { effects: 'fadeIn'} }," +
                                                              "contentUrl: '" + urlHelper + "'" +
                                                              "});" +
                                                              "});" +
                                                              "</script>" +
                                                              "<style>.k-link {font-weight: bold;}</style>"));
        }
    }
}

}

当我设置一个断点并获取这段代码时,它告诉我var urlHelper为null,尽管我不确定为什么。

var urlHelper = new UrlHelper(eventMessage.Helper.ViewContext.RequestContext)
                .RouteUrl("Nop.Plugin.Widgets.Modifications.Admin.ManufacturerAttachments",
                    new RouteValueDictionary { { "manufacturerId", manufacturerId } });

有人知道为什么这可能为空吗? 谢谢。

当然,当我发布问题时,我看到了问题,我忘记了从复制的路线中更改代码。 有时复制和粘贴是我最大的敌人。

必须将categoryId更改为ManufacturerId,如下所示:

routes.MapLocalizedRoute("Nop.Plugin.Widgets.Modifications.Admin.ManufacturerAttachments", "Plugins/Admin/ManufacturerAttachments/{manufacturerId}",
            new { controller = "ModificationsWidget", action = "ManufacturerAttachmentsAdmin" },
            new { categoryId = @"\d+" },
            new[] { "Nop.Plugin.Widgets.ModificationsWidget.Controllers" });
        route9.DataTokens.Add("area", "admin");

这个new { categoryId = @"\\d+" },这个new { manufacturerId = @"\\d+" },

抱歉,不知道我怎么想念:(

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM