Customization of bread crumbs

Feb 19, 2010 at 6:21 PM

I'm using the MvcSitemapProvider for a few things right now, one of which is breadcrumbs.

I was wondering what kind of customizations are possible.

For instance:

1. If I wanted an edit screen to show the id parameter, can I do that (IE Controller > Action > Id or Controller > Action Id, etc.)?

2. Is there any way to compartmentalize things arbitrarily? For instance, lets say I have a contract, with a partner that I can edit. I'd have a setup with ContractController and PartnerController, and my breadcrumbs would in turn be "Home | Contract | Edit" and "Home | Partner | Edit". Is there any way I could have it be "Home | Contract | Partner | Edit" to more accurately represent the true layout of the interface, or am I asking too much? Basically, I'd be asking if I could arbitrarily put controllers / actions under another controller, something like this:

<node controller>

    <node controller>

        <node action />

    </node>

</node>

===

Just some thoughts for a little deeper control.

/ Michael /

Coordinator
Feb 22, 2010 at 1:10 PM

1) Perfectly possible, set the SiteMap.CurrentNode's title from within the action method and you are done.

2) Also possible, you would have to make sure that your Web.sitemap contains this structure and breadcrumbs will automatically follow this.

Feb 22, 2010 at 2:29 PM

1) Ah, I see. I will just write a few attributes for that then. Thank you.

2) Huh... I could have SWORN that the last time I tried that, even on 1.1.0, that that wouldn't work for me. Color me embarassed for asking a stupid question...

/ Michael /

Feb 22, 2010 at 3:24 PM

So having played with this a bit now, I've been pleasantly surprised to find that the bread crumbs will remember the id parameters in my heirarchy I've built up.

Meaning that I can have "Menu > Controller 1 > Edit ### > Controller 2 > Edit Other###". This is after assigning said ###'s via my breadcrumb attribute I made. I found that interesting.

A quick question though, why, if it remembers this much, would the links that are generated not include all of the original route values? Something like this:

 

            var urlHelper = new UrlHelper(filterContext.RequestContext);
            if (filterContext.RouteData.Values.ContainsKey("id") &&
                filterContext.RouteData.Values["action"].ToString() == "Edit")
                SiteMap.CurrentNode.Title = SiteMap.CurrentNode.Description + " " + filterContext.RouteData.Values["id"];
            SiteMap.CurrentNode.Url = urlHelper.Action(filterContext.RouteData.Values["action"].ToString(),
                                                       filterContext.RouteData.Values["controller"].ToString(),
                                                       filterContext.RouteData.Values);

            var urlHelper = new UrlHelper(filterContext.RequestContext);
            SiteMap.CurrentNode.Url = urlHelper.Action(filterContext.RouteData.Values["action"].ToString(),
                                                       filterContext.RouteData.Values["controller"].ToString(),
                                                       filterContext.RouteData.Values);

Seems like it would give you back more accurate links that way...

 

/ Michael /

Coordinator
Feb 23, 2010 at 6:57 AM

Urls are actually generated in this manner, but are being cached if cache is enabled.

Feb 23, 2010 at 1:11 PM

Is there something special you have to do to enable that? I have all the isDynamic stuff in my sitemap XML, but I had to put the above lines in my Breadcrumb Attribute to get that to work.

/ Michael /