asp.net mvc - URL Routing Categories and Sub-Categories -
i've searched long time resolution of problem didn't found one..
i think, i'm not 1 has task , hope answer.
my website stores products.. many products. these products have 1 or more categories (or subcategories). retrieve product in correct category not problem. add id of @ end of product name like: http://localhost.com/products/details/books/romance/romeo-and-julia-3245. controller products , action details.
but best solution clean urls if want list products of 1 category? problem is, 1 sub-category exist more once. example:
http://localhost.com/products/list/games/romance
http://localhost.com/products/list/books/romance
if call list action in products controller, cannot detect if sub-categaory "romance" related games or books.
how can solve issue?
best regards
you may try write 2 routes actionresult list
, use parameters: if actionlink
contains parameter called games
takes route "games"
, if books
- takes route "books"
routes.maproute( name: "games", url: "{controller}/{action}/games/romance", defaults: new { controller = "products", action = "list", games = urlparameter.optional} ); routes.maproute( name: "books", url: "{controller}/{action}/books/romance", defaults: new { controller = "products", action = "list", books = urlparameter.optional} );
i'm not sure fits needs, can play logic.
Comments
Post a Comment