Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC page/subpage routing

I'm try to figure out how to handle the following scenario. In general, i have a bunch of records in a table. All of these have ID and ParentID fields to form a tree.

Page1
 - Page2
 - Page3
Page4
 - Page5
 -- Page6

Now, i want my routes for Page3 and Page6 to be like /Page1/Page6 and /Page3/Page5/Page6 respectivelly. That is, i want to include all parents in the URL.

How to set my controller action/routing to achieve the above result?

Edit: Forgot to mention that the above structure will be dynamic - nodes can be added/deleted/change parent, etc.

like image 796
ciscocert Avatar asked Nov 14 '22 16:11

ciscocert


1 Answers

You could use a wildcard match.

A possible route:

routes.MapRoute("SomeName", "{*Page}", new { controller = "ControllerName", action = "ActionName" });

and in the action accept the string Page, and parse it manually, perhaps with a split?

This might also be useful: URL Routing

like image 76
ccook Avatar answered Dec 19 '22 03:12

ccook