views:

30

answers:

2

Hi, I'm trying to build up a proper routing scheme for my products section in MVC 2. I've got the following criteria:

Links of the format

/Products/(MX[0-9]+) and /Products/(BDL[0-9A-Z_])

Need to route to ProductsController.Show(Id = $1)

Links of the format

/Products/([a-zA-Z0-9/]+)

Example: http://www.mysite.com/Products/Cameras/Digital/

Need to route to ProductsController.List(Category = $1)

Then on top of this, I want links like

/Products/AddToCart/{1} to work normally.

So far I've been able to get the above two to work fine through a relatively hack-ish method (all past /Products/ is routed to show, where some conditional logic redirects to .List(Category) if the start of the input isn't MX or BDL

I'm not happy with the current implementation and am open to some help. Thank you in advance.

+2  A: 

Use regular expression constraints for your routes and place them with AddToCart first, MX and BDL second, and the catch all products last. If you'd like even more control than that, you can create custorm routes.

Yuriy Faktorovich
Ok, but here's my problem, I've got that for splitting up my category/product lookup nicely now.But how to I distinguish between `Something/Like/This` and `An/Action/With/Parameters`Basically I would like it to check for an action first... Does that make any sense?
Aren
A: 

I don't recall the syntax off the top of my head, but you can add regex constraints on your routes so that they route to different places.

GalacticCowboy