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

Changing previous node title #82

Closed ouardia-y closed 3 years ago

ouardia-y commented 3 years ago

Hi,

I'm wondering if there's a way to change a previous node title. For example I have the following:

[Breadcrumb("Clients", FromAction = "MethodA", FromController = typeof(HomeController))]
public ActionResult Clients()
{
    return view();
}

[Breadcrumb("Client Details", FromAction = "Clients", FromController = typeof(HomeController))]
public ActionResult ClientDetails(int id)
{
    return view();
}

When I arrive to Client Details, I would like the breadcrumb to look like the following: MethodA / Clients (123)/ Client Details

I'm not sure if this is do-able but it would be great! If you need any clarifications, I'd be more than happy to further explain.

zHaytam commented 3 years ago

Hello,

SmartBreadcrumbs lets you create/use manual breadcrumb nodes specifically for this issue (dynamic values).
You can't change previous nodes, but you can handle the creation of the nodes in ClientDetails so that they include the received id.

Here are some resources to look at:

Basically, it'll look like this:

[Breadcrumb("Clients", FromAction = "MethodA", FromController = typeof(HomeController))]
public ActionResult Clients()
{
    return view();
}

public ActionResult ClientDetails(int id)
{
    // Create 3nodes here, MethodA, Clients (123) and Client Details
    // Use them in ViewData["BreadcrumbNode"] = clientDetailsNode; (last node)
    return view();
}
ouardia-y commented 3 years ago

Hi, thank you so much for your reply. I did try that yesterday but found my issue within your example.

If I have Method A, Method B, Method C, Method D, once I arrived to method D, I didn't add the previous manual breadcrumbs. I simply let the default take over. Which wasn't the correct approach.

Everything works now on my end, I'll close this issue.

Once again, thank you!