I trying to create routes for a resource with an array of homogeneous parameters.
URL would look like this: products/category/{categoryId1}/{categoryId2}/.../brand
Use a custom handler, like the one I posted in this answer.
Might need some adjustments, but something like this should work:
public class ProductsRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
IRouteHandler handler = new MvcRouteHandler();
var vals = requestContext.RouteData.Values;
vals["categoryID"] = vals["categories"].Split("/");
vals["brandID"] = vals["brands"].Split("/");
return handler.GetHttpHandler(requestContext);
}
}
// in the route:
routes.MapRoute(
"test",
"products/category/{*categories}/brand/{*brands}",
new { Controller = "product", Action = "getproducts"}
).RouteHandler = new ProductsRouteHandler ();