I know you could make a helper pretty easily given the data. So, if possible, please only submit answers that also include getting the data.
To get start first create an ASP.NET Core MVC project. I am using Visual Studio. Once it is done, install the nuget package SmartBreadcrumbs . Once it is done, we need to add the following code in the Program.
Breadcrumbs are a secondary navigation aid that helps users easily understand the relation between their location on a page (like a product page) and higher level pages (a category page, for instance).
It helps us to reduce code duplication. In other word a partial view enables us to render a view within the parent view. The partial view is instantiated with its own copy of a ViewDataDictionary object which is available with the parent view so that partial view can access the data of the parent view.
We are using an action filter for this.
...
public override void OnActionExecuting(ActionExecutingContext filterContext) { var controller = (Controller) filterContext.Controller; Breadcrumb[] breadcrumbs = _breadcrumbManager.PushBreadcrumb(_breadcrumbLinkText); controller.ViewData.Add(breadcrumbs); }
before you mention it, I too have a distaste for service location in the filter attributes - but we are left with few options. IBreadcrumbManager looks like this:
public interface IBreadcrumbManager { Breadcrumb[] PushBreadcrumb(string linkText); }
The implementation puts Breadcrumb objects into the Session. The Url is HttpContext.Current.Request.RawUrl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With