Hassan Abbas Hassan Abbas - 2 months ago 23
ASP.NET (C#) Question

override default method route from plugin in nopcommerce in 3.8

I want to override search controller. When I try to install a plugin, I get an error exception what multiple type were found for the controller named

Catalog
.


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.


And my route priority is most(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;
}
}

Div Div
Answer

You can override your route like this:

When you override route, then you should use MapLocalizedRoute(not MapRoute) which is override localized route. Here you are trying to define route which is already define.

Here do not use MapRoute use MapLocalizedRoute in this way.

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

Edit:

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

/search is default route of product search, you can see in Nop.Web > Infrastructure > RouteProvider.cs

Hope this helps!