zHaytam / SmartBreadcrumbs

A utility library for ASP.NET Core (both MVC and Razor Pages) websites to easily add and customize breadcrumbs.
https://blog.zhaytam.com/2018/06/24/asp-net-core-using-smartbreadcrumbs/
MIT License
161 stars 77 forks source link

Breadcrumbs not showing up for subfolder pages in Razor app .NET6 #108

Open rdkyle opened 1 year ago

rdkyle commented 1 year ago

I have a folder structure of Pages/Products/Product and the breadcrumbs work fine in the root and Products page but nothing shows in the sub folders of the Products folder for the different products. What else do you need to know from me to help resolve the issue?

Thanks

techtoniq commented 8 months ago

I had the same problem, with a Pages/Users/User hierarchy, and it was caused because my User page was called Index.cshtml even though it contained a model called UserPageModel.

When the BreadcrumbManager initialises the node hierarchy at startup, it string slices the page type name to generate the node key, so in my case the node hierarchy had a node with a key of "/Users/User". But when the tag manager attempts to generate the breadcrumb when the page is displayed, because the filename of the page is Index.cshtml, it means it is looking for a node with a key of "/Users/Index" and doesn't find it, so only the default breadcrumb is displayed.

The solution in my case was to make sure that the model name in the Razor page matched the file name.

Hope this is helpful for solving you issue.