nopcommerce 试图在管理面板中添加自定义选项卡
nopcommerce trying to add custom tab in admin panel
好的,对于类别编辑页面,我在 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 } });
有人知道为什么它可能为空吗?
谢谢
我的天啊,当然是对的,因为我 post 我的问题我看到了问题,我忘了更改我复制的路由中的代码。有时复制和粘贴是我最大的敌人。
必须像这样将 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+" },
对不起各位,我不知道我是怎么错过的:(
好的,对于类别编辑页面,我在 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 } });
有人知道为什么它可能为空吗? 谢谢
我的天啊,当然是对的,因为我 post 我的问题我看到了问题,我忘了更改我复制的路由中的代码。有时复制和粘贴是我最大的敌人。
必须像这样将 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+" },
对不起各位,我不知道我是怎么错过的:(