开发者

ASP.NET MVC: Have total control over the URL

开发者 https://www.devze.com 2022-12-24 17:19 出处:网络
I am developing a website that has nested categories. I would like the categories to be in the url such as something like this

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. Ho开发者_如何学Gow can I develop something like this in asp.net mvc?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号