views:

102

answers:

1

Hi, is it possible to route an hiearchical path to map an relation from the database as follows:

Lets say I have an tuple/entity "page" with an m-t-m relation to a "page" (it selfe) and I want to be able to combine the slug-value of each page to find an appropriate page, like so:

mydomain.com/firstpage/secondpage/thirdpage

where firstpage, secondpage and thirdpage is of type "page" and the third page references to the second page etc.

How would you implement this with ASP.Net MVC Routing?

+1  A: 

Ok, think I solved it!

I found out that there is a * (catch-all parameter) that can be used when routing.

For example:

routes.MapRoute(
    "Pages",
    "{*pageQuery}",
    new { controller = "Page", action = "GetPage" }
);

Then in my controller I can use regular expressions or a simple split to resolve each part of the slug. :)

Mickel
Are you sure you want to rely on the catch-all? That sort of negates the possibility of using the routes, as you end up turfing the routing logic into the controller.
Dan Atkinson
Hmm, that's true. However, if I place this after/below my default route(s) it will only fall back on this one if no other route satisfies the request.But I am open for suggestions and discussion. Do you have any better ideas? :)
Mickel