views:

3523

answers:

2

How can dynamic breadcrumbs be achieved with ASP.net MVC?

If you are curious about what breadcrumbs are:

What are breadcrumbs? Well, if you have ever browsed an online store or read posts in a forum, you have likely encountered breadcrumbs. They provide an easy way to see where you are on a site. Sites like Craigslist use breadcrumbs to describe the user's location. Above the listings on each page is something that looks like this:

s.f. bayarea craigslist > city of san francisco > bicycles

EDIT

I realize what is possible with the SiteMapProvider. I am also aware of the providers out there on the net that will let you map sitenodes to controllers and actions.

But, what about when you want a breadcrumb's text to match some dynamic value, like this:

Home > Products > Cars > Toyota

Home > Products > Cars > Chevy

Home > Products > Execution Equipment > Electric Chair

Home > Products > Execution Equipment > Gallows

... where the product categories and the products are records from a database. Some links should be defined statically (Home for sure).

I am trying to figure out how to do this, but I'm sure someone has already done this with ASP.net MVC. Thanks for any guidance!

+8  A: 

There is a tool to do this on codeplex: http://mvcsitemap.codeplex.com/

Edit:

There is a way to drive a SiteMapProvider from a database: http://www.asp.net/Learn/data-access/tutorial-62-cs.aspx

You might be able to modify the mvcsitemap tool to use that to get what you want.

ICodeForCoffee
That provider on codeplex is good, but I can't figure out how to pass route parameters to the MvcSiteMapNode from the action method. There is documentation on doing this from the Web.Sitemap, but not from the action method. Can anyone advise?
Ronnie Overby
+1  A: 

Maarten Balliauw's MvcSiteMapProvider worked pretty well for me.

I created a small mvc app to test his provider: MvcSiteMapProvider Test

Ronnie Overby
How did you create dynamic fields with custom routes ?
Barbaros Alp
I don't remember. I take my answer back, though. It didn't work that well for me. I ended up coding the menu items by hand where needed.
Ronnie Overby