ASP.NET MVC - Simple Breadcrumbs (SiteMap)

I have developed an ASP.NET MVC 2 application and I want to place simple sitemap on each page as follows:

Home> Movies> Details

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

How can i achieve this? I would like to put it on my main page.

Thanks!

+2
source share
2 answers

If it is always equal to the URL, the easiest way would be to use it using the following:

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

menuitems will now contain the menu items needed to complete a simple foreach loop and create your menu.

+1
source

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

It can be used to create breadcrumbs (which you are probably asking about), as well as site maps.

MvcSiteMapProvider as the name implies that the ASP.NET MVC implementation of SiteMapProvider for the ASP.NET MVC framework. Aimed at ASP.NET MVC 2, it provides XML sitemap functionality and interoperability with the classic ASP.NET sitemap controls, such as the SiteMapPath control for creating breadcrumbs and control menus.

Based on areas, controllers, and actions, method names, rather than hard-coded link URLs, site map nodes are fully dynamic, based on which is used in the application. The dynamic nature of ASP.NET MVC in MvcSiteMapProvider: There are numerous extensibility points that allow you to extend the basic functionality.

+2
source

Source: https://habr.com/ru/post/1345127/


All Articles