What is the appropriate route design for this ASP.NET MVC application?
My url http://server/region/section/item
Now if someone goes to http://server/us/ I want to display a page to choose a section if 开发者_StackOverflowsomeone goes to http://server/us/beer/ I want to display a list of all beers.
My question is should I just have 1 route with defaults and then return different views depending on how much the URL is filled in or should I create multiple routes going to the same controller different actions? or even different controllers, I just want to know what the best practice is.
The typical route looks like this:
http://www.domain.com/controller/action/id [domain/controller/action/id]
In your case, it's short one part: http://server/us/beer [domain/controller/action?/?]
As Robert Harvey said, you wouldn't want to have an action for every product. So how about something like: http://server/us/product/beer [domain/controller/action/id]
- domain = server
- controller = us (tho, this doesn't seem like it would be a good name for the controller)
- action = product
- id = beer
Then you'd develop a product view that would show the beer data to your visitors.
This isn't architect-ed very well, but without knowing your situation it would be difficult for anyone to answer this. I hope this helps though.
In your particular case, "beer" can probably be a filter to a controller action, rather than another controller action, in which case you need only one route entry.
It doesn't seem wise to create a strategy that will require you to add new routes, controller methods and/or views every time you add a product category. Unless, of course, you want to highly customize each category's look and behavior.
精彩评论