Creation of breading knots. Path in asp.net MVC

I am trying to create breadcrumbs that include user-viewed pages, as an example:

Home → Products → Smartphones → .....

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

+5
source share
2 answers

There is an open source project called MvcSiteMapProvider that I contributed to this, which makes it pretty easy. The project is available on NuGet.

Basically, you are setting up a site map with all of your pages. A sitemap can be configured in XML, code, or another data source. The sitemap is then cached and shared between users. When the user navigates to the URL that is configured on the site map (either as a URL or as a dictionary of route values), he will use the relative position on the map to determine how to create breadcrumbs on the home page.

There is a walkthrough of installing and using its functions here: MvcSiteMapProvider 4.0 - test drive

+4
source

Have you seen the open source solution MvcBreadCrumbs ? There are several ways to do this using the Nuget package. You can use attributes in controller methods, for example:

[BreadCrumb(Label="Widget")] public ActionResult ... 

or optionally add a call to the static method to override the label if it is data dependent:

 [BreadCrumb(Label="Widget")] public ActionResult Get(int id) { [make db call] BreadCrumb.SetLabel(db.ItemDescription); return view(dbModel); } 
+1
source

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


All Articles