好吧,对于类别编辑页面,我已经在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 } });
有人知道为什么这可能为空吗? 谢谢。
答案 0 :(得分:0)
当然,当我发布问题时,我看到了问题,我忘记了从复制的路线更改代码。有时候复制和粘贴是我最大的敌人。
必须将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+" },
对不起,不知道我是怎么想的:(