问题
Is it possible to route an hierarchical path to map a relation from the database as follows:
Let's say I have an tuple/entity "page" with an m-t-m relation to a "page" (itself) 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
are of type "page" and the third page references to the second page etc.
How would you implement this with ASP.NET MVC routing?
回答1:
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. :)
来源:https://stackoverflow.com/questions/1315815/routing-an-hierarchical-path-from-db-with-asp-net-mvc