简体   繁体   English

通过覆盖插件nopCommerce 3.3中的GenericPathRoute.cs来更改URL路由

[英]Change URL Routing by overriding GenericPathRoute.cs in Plugin nopCommerce 3.3

I am trying to create a plugin which will override the TopicsDetails.cshtml page. 我正在尝试创建一个将覆盖TopicsDetails.cshtml页面的插件。 I added a route like this: 我添加了这样一条路线:

      routes.MapRoute("Nop.Plugin.Other.CustomTopic.ViewCustomTopic", "{SeName}",
                        new { controller = "CustomTopic", action = "TopicDetails", SeName = UrlParameter.Optional },
                        new[] { "Nop.Plugin.Other.CustomTopic.Controllers" });

This is getting all the {SeName} to my CustomTopicController .Even the products SeName. 这是将所有{SeName}传递给我的CustomTopicController。即使是产品SeName。

If I add this instead of the older one: 如果我添加此而不是旧版本:

       routes.MapRoute("Nop.Plugin.Other.CustomTopic.ViewCustomTopic",
                        new { controller = "CustomTopic", action = "TopicDetails" },
                        new[] { "Nop.Plugin.Other.CustomTopic.Controllers" });

I get an error because the TopicDetails(int itemId) Action receives an integer which is not provided as we know that GenericPathRoutes.cs Provides that integer. 我收到一个错误,因为TopicDetails(int itemId)Action接收到一个未提供的整数,因为我们知道GenericPathRoutes.cs提供该整数。

How can I override the Rules of GenericPathRoutes.cs to do it so that only the topic SeName would hit my Controller or is there other way to do that kind of work or is it even possible to do? 我怎样才能覆盖GenericPathRoutes.cs的规则来做到这一点,这样只有SeName主题会命中我的Controller,或者有其他方式来做这种工作,或者甚至可以这样做?

Recently i wrote an article which shows how to override localized route and i used the TopicDetails view as an example. 最近我写了一篇文章,展示了如何覆盖本地化路由,我以TopicDetails视图为例。 There article is here . 有文章在这里 Inshort, your route provider shall look like this; Inshort,您的路线提供者应如下所示;

public class RouteProvider : IRouteProvider
{
    private const string NAMESPACES = "Nop.Plugin.Misc.Custom.Controllers";
    private const string CONTROLLER = "MiscCustom";

    public void RegisterRoutes(RouteCollection routes)
    {     
        //Public Override
        routes.MapGenericPathRoute("Plugin.Misc.Custom.GenericUrl",
            "{generic_se_name}",
            new { controller = "Common", action = "GenericUrl" },
            new[] { NAMESPACES });

    }

    public int Priority
    {
        get { return Int32.Max; }
    }
}

我不确定我是否理解你的问题可以通过添加id = UrlParameter.Optional在这里尝试任何id参数是可选的它不会抛出该错误

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

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