Handle Multiple Categories in Example

Jan 28, 2010 at 7:55 PM

How would you handle multiple categories in the example that is provided in the download? For example:

 

/products/dvd/action-adventure

 

OR

 

/products/electronics/computers/dell/laptops

 

What would the routing looking like? What would the site map look like?

 

Thanks.

Coordinator
Jan 29, 2010 at 8:26 AM

I would do this with a catch-all route. Sitemap node can then be dynamic with the catchall parameter as dynamic value.

Jan 29, 2010 at 3:11 PM

I tried this and I'm not getting the results I expected. I tweaked your example project as follows:

I added a wildcard parameter to the route for the categories

routes.MapRoute(
                "Products",                                              // Route name
                "{controller}/{action}/{*categories}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            )
routes.MapRoute(
                "Products",                                              // Route name
                "{controller}/{action}/{*categories}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

 

I then modified the products controller to grab the last category in the categories parameter and use that as the id. A URL like this

/Products/List/action-adventure/DVD

Does produce the list of all DVDs, but the breadcrumb looks like this

home > prodcuts > dvd

How can we get all categories to be part of the breadcrumb?

Coordinator
Jan 30, 2010 at 10:10 AM

I guess having a custom sitemap provider here that depends on the products database would be the better option.