views:

48

answers:

1

Hi,

i need to model the following scenario, but I can't get it working with the MvcSitemapProvider (i think my problem also maps directly to the default SiteMapProvider). I want to get the default breadcrumbs control to work properly with my dynamic data.

I have a list of products which are grouped by category which have a parent-category

  • ParentCategory
    • Category
      • Product

I want to be able to use the following url(s):

(1) /Products
(2) /Products/MainCategory
(3) /Products/MainCategory/Category
(4) /Products/MainCategory/Category/Product

Obviously my solution below is not optimal.

The Products node in the Sitemap doesn't have ChildNodes, so they won't show up in my Menu.

I've created an intermediary object which adds the maincategories and categories so they show up in my menu. But this won't fix the problem as other controls (breadcrumbs) just say that I am on /Products.

Should I change my routes or change my sitemap definition? Or maybe something else?


I currently have the following:

  • 2 Routes
    1 for /Products, /Products/MainCategory and /Products/MainCategory/Category -> mapping to ProductsController.Index()
    1 for /Products/MainCategory/Category/Product -> mapping to ProductsController.Product()
  • 1 entry in the Sitemap
    with dynamicParameters defined (MainCategory;Category)

Global.asax Route definition:

    routes.MapRoute( _
        "Product", _
        "Products/{MainCategoryName}/{CategoryName}/{ProductName}", _
        New With {.controller = "Products", .action = "Product"} _
    )

    routes.MapRoute( _
        "Products", _
        "Products/{MainCategoryName}/{CategoryName}", _
        New With {.controller = "Products", .action = "Index", .GroupName = "", .CategoryName = ""} _
    )

I have the following entries in my sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
  <mvcSiteMapNode controller="Home" action="Index" title="Home" description="Homepage">
    <mvcSiteMapNode controller="Products" action="Index" title="Products" description="" isDynamic="true" dynamicParameters="MainCategoryName;CategoryName" />
  </mvcSiteMapNode>
</siteMap>
+1  A: 

I'm currently using a custom SiteMapProvider. I'm still also maintaining custom routes they are in no way related.

Ropstah