thelarz / MvcBreadCrumbs

Custom BreadCrumbs for MVC
GNU General Public License v3.0
43 stars 28 forks source link

Add an Add(Url, Label) method #5

Closed GorillaSpring closed 8 years ago

GorillaSpring commented 8 years ago

Be able to add a BreadCrumb from within a method.

Usage:

            BreadCrumb.Clear();  // note, this does not currently exist.  Another issue loged!
            BreadCrumb.Add(Url.Action("Index", "Help"), "Help");  // add a fist level breadcrumb.
            return RedirectToAction("SubHelpAction", "Help")

My Solution (May not be the appropriate solution!)

Add to BreadCrumb.cs

 public static void Add(string Url, string Label)
        {
            // get a key for the Url.
            var key =
               Url
               .ToLower()
               .GetHashCode();

            var Current = new StateEntry().WithKey(key)
             .WithUrl(Url)
             .WithLabel(Label);

            StateManager.GetState(SessionProvider.SessionId).Crumbs.Add(Current);
        }