2

I have developed a ASP.NET MVC 2 application and I want to put a simple breadcrumbs (sitemap) in each page like this:

Home > Movies > Details

It is equal the URL: http://localhost/home/movies/details

How can I achieve it? I would like to put it in my master page.

Thanks!

Charlino
  • 15,802
  • 3
  • 58
  • 74
Beginner
  • 65
  • 2
  • 5
  • SiteMap? Don't you mean breadcrumbs? – Charlino Mar 15 '11 at 19:57
  • yes you are correctly, breadcrumbs. Actually I'm web forms developer. There, it is known SiteMap. – Beginner Mar 15 '11 at 20:01
  • possible duplicate of [How can dynamic breadcrumbs be achieved with ASP.net MVC?](http://stackoverflow.com/questions/1066777/how-can-dynamic-breadcrumbs-be-achieved-with-asp-net-mvc) – Charlino Mar 15 '11 at 20:04
  • possible duplicate of [How would you implement a breadcrumb helper in asp.net mvc?](http://stackoverflow.com/questions/66009/how-would-you-implement-a-breadcrumb-helper-in-asp-net-mvc) – Charlino Mar 15 '11 at 20:06
  • yes, it is duplicated. What I need to do? – Beginner Mar 15 '11 at 20:08
  • I don't think there is anything you can do... just wait for other users to come along and vote to close it too. :-) – Charlino Mar 15 '11 at 20:10
  • My pleasure, hope you enjoy using Stackoverflow :-) – Charlino Mar 15 '11 at 20:13

2 Answers2

2

I would recommend using MVCSiteMapProvider. It's available as a NuGet package.

It can be used to generate breadcrumbs (which you are probably asking about) and also site maps.

MvcSiteMapProvider is, as the name implies, an ASP.NET MVC SiteMapProvider implementation for the ASP.NET MVC framework. Targeted at ASP.NET MVC 2, it provides sitemap XML functionality and interoperability with the classic ASP.NET sitemap controls, like the SiteMapPath control for rendering breadcrumbs and the Menu control.

Based on areas, controller and action method names rather than hardcoded URL references, sitemap nodes are completely dynamic based on the routing engine used in an application. The dynamic character of ASP.NET MVC is followed in the MvcSiteMapProvider: there are numerous extensibility points that allow you to extend the basic functionality offered.

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
  • 1
    I have bad experiences with MvcSiteMapProvider when number of dynamic nodes is very high (20.000+). – noocyte Jan 31 '13 at 11:18
1

If it is always equal to the URL, the absolute simplest thing would be to make use of that by using something like this:

var menuitems = Request.Url.AbsolutePath.Split("/".ToCharArray(),
    StringSplitOptions.RemoveEmptyEntries);

menuitems would now contain the menu items you need to perform a simple foreach loop and build your menu.

Mikael Östberg
  • 16,982
  • 6
  • 61
  • 79