开发者

Setting up a routing scheme in ASP.NET MVC, need some advice

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_])

开发者_JAVA百科

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜