Luke101
Luke101

Reputation: 65298

ASP.NET MVC: Have total control over the URL

I am developing a website that has nested categories. I would like the categories to be in the url such as something like this

http://www.dmoz.org/Computers/Programming/Component_Frameworks/NET/Chats_and_Forums/

as you can see in the above url the categories are in the url itself. How can I develop something like this in asp.net mvc?

Upvotes: 1

Views: 286

Answers (2)

Mike
Mike

Reputation: 6239

Look up URL Routing:

As per the above, you'll just need to add a route(s) to the routing table using placeholders in your URLs for your categories / sub-categories etc. This means any links to your pages, or anyone directly writing in the URL will go to the routing table and try to match it up - make sure the default 'catch-all' route is last in your list of routes defined.

When you're building up these URLs for links etc to click in your views, then I would probably create a Html helper that builds up a string with your controller/category/sub-category syntax.

Upvotes: 0

Zachary Scott
Zachary Scott

Reputation: 21198

You could catch them as parameters {*id} then parse them in the controller.

Upvotes: 1

Related Questions