3

I have seen some posts about navigation and breadcrumbs but did not find the exaxt same problem. However if there is, please forgive and point me to it. Thank you.

My case :

Interests                   Profiles
|                       |
|_Interest Area 1               |-Profile Area 1
|   |                       |
|   |_Interest Area 1.1             |_List of Books
|       |                       |
|       |_List of Books                 |_Book Detail
|           |
|           |_Book Detail
|_Interest Area 2
    |
    |_List of Books
        |
        |_Book Detail

The hierarchy is stored in the database. The entry points Interests and Profiles are fixed. From there I don't know what the children will be.

When there is no child left anymore, the books get retrieved based on the value of the last selected (sub)category.

I have two problems here: 1st: Creating the appropriate routes. The way I would like it is:

/books/{id}/{interestareaname}/{subinterestareaname}/{books}/{page}

where interestareaname is added for user friendly urls and keeps getting repeated as long you go down the hierarchy. The output would then be: /books/1/project-management/prince2/books/1 this shows the prince2 books on paged listpage page 1.

But when there is only one level it the route contains only one interestareaname and thus becomes this:

/book/{id}/{interestareaname}/{books}/{page}

What I did to solve problem number 1:

    routes.MapRoute(
        "Details",
        "view/details/{id}/{booktitle}",
        new { controller = "book", action = "Details", id = "*", booktitle= "*"});

    routes.MapRoute(
        "interests",
        "books/{id}/{level1}/{level2}/{level3}/{page}",
        new { controller = "book", action = "books", level1 = "*", level2 = "*", level3 = "*", id = "0", page = UrlParameter.Optional }
    );
    routes.MapRoute(
        "profiles",
        "books/{id}/{level1}/{level2}/{level3}/{page}",
        new { controller = "book", action = "books", level1 = "*", level2 = "*", level3 = "*", id = "0", page = UrlParameter.Optional }
    );

I got to this by stating that a max level should be set. That is only because I didnt know how to make it more dynamic.

The problem now is to differentiate between the interests categories and the profile categories. I did that by creating a same route, but with different name and added the route name in the sitemap creation.

The 2nd problem I have is the sitemap and the breadcrumbs. I use the MVCsitemapprovider and the DynamicNodes functionality.

With the sitemap I have a problem showing the details page. Because the books will appear both on profiles and on interests. And some books will appear in multiple interest areas or profiles. In each case I would like to see the path I used to get to that book.

First I added the detail pages for each book to the sitemap, but that was crazy. And creates duplicate entries which are not handled very well by sitemaps. Other option was to pass the routedata on the list page to the details page by querystring, but that looked awful and I have then to add logic to parse the querystring to mimic the breadcrumb, which will be hard, since I only have the ID then of the lowest level.

I have spent now many nights and I still can´t figure it out. If some one can help or point me to the right direction I am very grateful.

Mounhim
  • 1,674
  • 1
  • 17
  • 32
  • The routes have been reduced to one single route, because the others were never reached (found out by using routedebugger). The problem about the paging in the list is solved by using UrlParameter.Optional. Now the only problem left is showing the breadcrumb when getting to the details page of a book. – Mounhim Feb 06 '12 at 22:06

1 Answers1

0

The only solution I found so far for myself is to actually create all possible routes, like:

        routes.MapRoute(
            "interest",
            "interest",
            new { controller = "books", action = "viainterest"},
            new { controller = "books", action = "viainterest" }
        );

        routes.MapRoute(
            "interest_1_details",
            "interest/{level1}/view/{id}/{booktitle}",
            new { controller = "books", action = "detailsviainterest_1, level1 = "*", id = 0, booktitle = "*" },
            new { controller = "books", action = "detailsviainterest_1" }
        );

        routes.MapRoute(
                       "interest2details",
                       "interest/{level1}/{level2}/view/{id}/{booktitle}",
                       new { controller = "books", action = "detailsviainterest_2", level1 = "*", level2 = "*", id = 0, booktitle = "*" },
                       new { controller = "books", action = "detailsviainterest_2" }
                   );


        routes.MapRoute(
                        "interestlevel_1",
                        "interest/{id}/{level1}",
                        new { controller = "books", action = "viainterestlevel_1, level1 = "*", id = 0 },
                        new { controller = "books", action = "viainterestlevel_1"}
                    );

        routes.MapRoute(
                       "interestlevel_2",
                       "interest/{id}/{level1}/{level2}",
                       new { controller = "books", action = "viainterestlevel_2", level1 = "*", level2 = "*", id = 0 },
                       new { controller = "books", action = "viainterestlevel_2}
                   );
        //and so on for level 3 and for profiles etc.

In the DynamicNodeManager I add all the categories hierarchically and also add all the items. Now I get a decent breadcrumb all the way to the detail page. And since the paths (routedata and actions) for each detailpage are different, even a book that appears in several categories displays the correct breadcrumb.

This solved my problem, but I am still thinking there should a better way. The problem with the current solution is that the tree will grow huge because of the detail items that are added to the nodecollection as well. The other downside is that the tree is generated at application start. Thus adding a new book, does not create a node, until I reset the web application.

So if there are other suggestions I am happy to see them. For now I can continue with the content, which it is all about in the end.

Mounhim
  • 1,674
  • 1
  • 17
  • 32