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

问题描述 投票:0回答:1

好吧,对于类别编辑页面,我在nopcommerce管理面板中添加了一个自定义选项卡,因此我尝试对制造商编辑页面执行相同操作,但选项卡的内容未显示。

admin image

这是我正在使用的代码:

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 } });

任何人都知道为什么那可能是空的?谢谢。

c# asp.net events model-view-controller nopcommerce
1个回答
0
投票

Omg当然正如我发布我的问题我看到问题,我忘了改变我复制的路线的代码。有时复制和粘贴是我最大的敌人。

不得不将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+" },

对不起伙计,不知道我是怎么错过的:(

© www.soinside.com 2019 - 2024. All rights reserved.