Create breadcrumbs Path in asp.net MVC

mmarques picture mmarques · Aug 23, 2013 · Viewed 11.3k times · Source

I'm trying to create a breadcrumbs that includes pages viewed by user, like the example:

Home -> Products -> Smartphones -> .....

Does anyone know how to do that in asp.net mvc 3 with razor view engine ? Or where i can find a good tutorial ?

Answer

NightOwl888 picture NightOwl888 · Aug 23, 2013

There is an open source project called MvcSiteMapProvider that I have been contributing to that makes this fairly easy. The project is available on NuGet.

Basically, you configure an sitemap with all of your pages. The sitemap can be configured in XML, code, or from another data source. The sitemap is then cached and shared between users. When a user navigates to a URL that is configured in the sitemap (either as a URL or as a dictionary of route values), it will use the relative position in the map to determine how to build breadcrumbs back to your home page.

There is a walk-through of installing and using its features here: MvcSiteMapProvider 4.0 - A Test Drive