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

How to name different Breadcrumb when having same action method and same controller #52

Closed tusharbsale closed 4 years ago

tusharbsale commented 4 years ago

Hi , I have question arises now how can i provide different Breadcrumb node name having same action method but with different input parameter.

here is my code public async Task<IActionResult> Index(bool Modal=false) { if (Modal==true) { return View("Modal"); // this will have link as [Breadcrumb("ModalTrue")] } else return View(config); // this will have link as [Breadcrumb("ModalFalse")] }

how can i achieve above?

zHaytam commented 4 years ago

Did you check https://github.com/zHaytam/SmartBreadcrumbs/wiki/4.-Manual-nodes ?

tusharbsale commented 4 years ago

Did you check https://github.com/zHaytam/SmartBreadcrumbs/wiki/4.-Manual-nodes ?

Yes. i have checked above link. I am using SmartBreadcrumbs v2.0.0 I am able to create a MvcBreadcrumbNode now but wondering how to established relation between parent and child nodes

for ex. I have below to nodes, var DiaryEntryNodeParent= new MvcBreadcrumbNode("GetJobNotification", "DiaryConfigController", "JobNotification", false, null, null); var DiaryEntryNodeChild = new MvcBreadcrumbNode("EditJobNotification", "DiaryConfigController", "Create", false, null,null); ViewData["BreadcrumbNode"] = DiaryEntryNodeParent;

any idea how to achieve same.?

zHaytam commented 4 years ago

Hello, right now it's possible by doing this:

var childNode2 = new MvcControllerBreadcrumbNode("Controller", "ViewData.Title")
{
    OverwriteTitleOnExactMatch = true,
    Parent = childNode1
};

Be aware that you must put the last child in the ViewData, not your first.

tusharbsale commented 4 years ago

Just spent some time and able to achieve what i was looking for. here is my working code

var DiaryEntryNodeParent= new MvcBreadcrumbNode("GetJobNotification", "DiaryConfig", "JobNotification", false, null, null);
                var DiaryEntryNodeChild = new MvcBreadcrumbNode("EditJobNotification", "DiaryConfig", "Create")
                {
                    OverwriteTitleOnExactMatch = true,
                    Parent = DiaryEntryNodeParent
                };
                ViewData["BreadcrumbNode"] = DiaryEntryNodeChild;