Reputation: 1897
I am using IRouterProvider for creating route description from attribute routing as suggested in this thread. The router provider is called and the routes are fetched.
I generate links for these specific actions by using Url.Action helper method, and the urls are generated for the custom routes as expected. However, when such a link is navigated the controller is not called. I got plain 404. Orchard is not even in the game.
My route provider looks like:
public IEnumerable<RouteDescriptor> GetRoutes()
{
var type = typeof(ShoppingCartController);
foreach (var meth in type.GetMethods())
{
var attr = meth.GetCustomAttribute<System.Web.Mvc.RouteAttribute>();
if (attr != null)
{
yield return new RouteDescriptor
{
Priority = 100,
Name = string.Format("ShoppingCart{0}Route", meth.Name),
SessionState = System.Web.SessionState.SessionStateBehavior.Required,
Route = new Route(attr.Template,
new RouteValueDictionary
{
{ "area", "XXXX.Features" },
{ "controller", "ShoppingCart" },
{ "action", meth.Name }
},
new RouteValueDictionary(),
new RouteValueDictionary
{
{ "area", "XXXX.Features" }
},
new MvcRouteHandler())
};
}
}
}
My controller method signature is:
[Themed]
[Route("cart/checkout")]
public ActionResult CheckOut() {...}
I tried to debug the problem, but I don't even know where to start. I am quite new to Orchard.
Thanks in advance
Upvotes: 2
Views: 405
Reputation: 13366
The code in route provider seems ok. There are a few things you can check:
RouteAttribute
and see if this one gets through. If so, then the attribute itself messes things up for some reason and the best option would be to mimic the attribute class and use that one instead to decorate actions.area
parameter is correct and equals to the module (not feature) name your controller is in (ie. the module project name).int.MaxValue
to make sure it's not hijacked by some other routeName
property and/or make sure it's really uniqueUpvotes: 1