chr2306 wrote:Ok, I shall put it in another way.
The fact that you've registered a route with URL 'Catalog/HomepageProducts' doesn't make
@Html.Action("HomepageProducts", "Catalog") to take your route. If you visit ~/Catalog/HomepageProducts directly in your browser then yes, your plugin will override the original render. But when you call
@Html.Action("HomepageProducts", "Catalog") directly, the route that is actually taking place should be:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Nop.Web.Controllers" }
);
which is defined in Global.asax.cs. :)
Indeed, but according to
http://msdn.microsoft.com/en-us/library/cc668201(v=vs.100).aspx:
Route matching is tried from the first route to the last route in the collection. When a match occurs, no more routes are evaluated.
And since I'm using Priority = 100 in my RouteProvider it is registered before the "Default"-route (and I verify this by way of debugging). So again, by way of logic, the "Default"-route should only be matched if my route is not matched first. And if @Html.Action does go by route table, then the route values should hit my defined route.
Might it be an issue with area or parameters?
Ok, let's put it this way. Imagine the URL defined in your route reads 'TestC/TestA' instead of 'Catalog/HomepageProducts', with everything else the same. So it eventually reads:
routes.MapLocalizedRoute("Nop.Plugin.Product.BoxedProductView.HomepageProducts",
"TestC/TestA",
new { controller = "BoxedProductController", action = "HomepageProducts" },
new[] { "Nop.Plugin.Product.BoxedProductView" }
);
Now tell me, which controller and action does this route correspond to? I have a feeling you are confused by the 'Catalog/HomepageProducts' URL part, but how the URL looks like is not indicative of how the @Html.Action("Catalog", "HomepageProducts") code will react.
Essentially your route is mapping to BoxedProductController, HomepageProducts action of Nop.Plugin.Product.BoxedProductView namespace. It is not like just because you format the route URL to look like Catalog/HomepageProducts, then your route will override the default render of Html.Action("Catalog", "HomepageProducts"). It will override if you visit
~/Catalog/HomepageProducts though.
What you can try instead is to use a route like:
routes.MapLocalizedRoute("Nop.Plugin.Product.BoxedProductView.HomepageProducts",
"TestC/TestA",
new { controller = "Catalog", action = "HomepageProducts" },
new[] { "Nop.Plugin.Product.BoxedProductView" }
);
Like this, your route table have 2 entries matching
Controller = Catalog and
Action = HomepageProducts, but with different namespace. And because your route have a higher priority, it'll be used eventually. But what is making the difference is not the URL, it's the name space. Notice that I am using TestC/TestA as the URL, but it doesn't matter in case of Html.Action(). :)