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

manually configure BreadcrumbNode gives exception in the service #12

Closed BR50Kab closed 5 years ago

BR50Kab commented 5 years ago

Hello,

I dont seem to get the manually node configuration to work. The annotation method works except for the action taking a parameter which is lost on clicking the breadcrumb. The manual node does not have a DefaultNode as parent. I upgraded to 1.4 but without succes.

I tried:

//[Breadcrumb(“ViewData.Title”, CacheTitle = true, FromAction = “Interaction.Index”)] public IActionResult Edit(Guid id) {

var parentNode = new BreadcrumbNode(“InteractionIndex”, “Index”, “Interaction”, id, null); var editInteractionNode = new BreadcrumbNode(“ViewData.Title”, “Edit”, “Interaction”, id, parentNode);

The id is the routevalue i need to pass.

I get an exception in services saying “Sequence contains no matching element

i have this one in HomeController

[DefaultBreadcrumb(“Home”, CacheTitle = true)] public IActionResult Index() { return View(); }

The Edit action in Interaction controller is in Home > Admin > Interaction > Edit

We use a LocalizedTaghelper derived from the original Taghelper, basically a copy paste of some functions and adding localization on the strings. This worked until i tried configuring a manual node. I also noted that some of the examples on this didnt match the number and order of prameters in the src. I followed source and could compile, running gives the exception.

Kind regards, Martien

zHaytam commented 5 years ago

Hello,

I will try this and get back to you asap.

BR50Kab commented 5 years ago

If i also add the annotation i dont get an exception in the service. Following below code it will show the "HocusPocus" title but when i click one deeper from the Edit view the "hocusPocus" is replaced with literally "ViewData.Title" (no substitution as with pure annotations). Clicking the breadcrumb results as before in an empty id.

As the BreadcrumbManager generates it's hierarchy by the attributes list i assume something here is wrong with the attributes. With annotation the attributes are generated with reflection but i havent seen anything in the code so far that generates the attributes for the manual nodes?

[Breadcrumb("ViewData.Title", CacheTitle = true, FromAction = "Interaction.Index")] public IActionResult Edit(Guid id) {

        //var attr = new BreadcrumbAttribute("Interaction.Index");
        var parentNode = new BreadcrumbNode("Interaction", "Index", "Interaction", id, null);
         var editInteractionNode = new BreadcrumbNode("HocusPocus", "Edit", "Interaction", id, parentNode);

        ViewData["BreadcrumbNode"] = editInteractionNode; 
zHaytam commented 5 years ago

When you use manual modes, they completly replace the attributes for that action (except for the default node). I still didn't find the time to test your code but I think I will later today, sorry!