asp.net - 覆盖 3.8 中 nopcommerce 插件的默认方法路由

标签 asp.net asp.net-mvc nopcommerce

我想覆盖搜索 Controller 。当我尝试安装插件时,出现错误异常,为名为 Catalog 的 Controller 找到了多种类型。

Multiple types were found that match the controller named 'Catalog'. This can happen if the route that services this request ('AdvanceSearch') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

我的路线优先级是最高(100)。

public void RegisterRoutes(RouteCollection routes)
    {
        // Product Search,
        routes.MapRoute("Plugin.Misc.Twigoh.Search",
         "Search",
         new { controller = "Catalog", action = "Search" },
         new[] { "Nop.Plugin.Misc.Twigoh.Search.Controllers" });


    }
    public int Priority
    {
        get
        {
            return 100;
        }
    }

最佳答案

您可以像这样覆盖您的路线:

当您覆盖路由时,您应该使用 MapLocalizedRoute(不是 MapRoute),它是覆盖本地化路由。在这里,您尝试定义已经定义的路线。

这里不要使用MapRoute,而是使用MapLocalizedRoute这种方式。

routes.MapLocalizedRoute("Plugin.Misc.Twigoh.Search",
                            "search/",
                            new { controller = "Catalog", action = "Search" },
                            new[] { "Nop.Plugin.Misc.Twigoh.Search.Controllers" });

编辑:

I want same route and functionality but default controller can't have "/" search feature little bit different

/search 是产品搜索的默认路由,可以在Nop.Web > Infrastructure > RouteProvider.cs 中看到

希望这有帮助!

关于asp.net - 覆盖 3.8 中 nopcommerce 插件的默认方法路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39912457/

相关文章:

asp.net-mvc - ASP.Net MVC 中的 self AJAX 更新部分 View / Controller 和复制 div

asp.net-mvc - 在 asp.net mvc Controller 中处理域事件

azure-devops - 为 nopCommerce 4.xx 工作 Azure DevOps(又名 VSTS)构建定义

asp.net - Soap 和 Rest Web 服务

c# - InvalidOperationException 调用 ResourceManager.GetString 时

C# 图像旋转

nopcommerce - 将数量部分添加到 nopcommerce2.2 中的 View /目录中的 _ProductBox.cshtml

c# - 批量插入,asp.net

c# - 我可以在 MVC 站点下的虚拟目录中拥有传统的 ASP.NET Web 应用程序吗?

.net - 想在Core Project中放一个4.6目录