Link to home
Create AccountLog in
Avatar of Eddie Shipman
Eddie ShipmanFlag for United States of America

asked on

Dynamic Breadcrumbs in C# MVC5 app

I need breadcrumbs for my MVC website in this format:

<span class="inline odd first"><a href="/">Home</a></span>
<span class="delimiter">></span>
<span class="inline even"><a href="#">Link 1</a></span>
<span class="delimiter">></span>
<span class="inline odd"><a href="#">Link 2</a></span>
<span class="delimiter">></span>
<span class="inline even"><a href="#">Link 3</a></span>
<span class="delimiter">></span>
<span class="inline odd"><a href="#">Link 4</a></span>
<span class="delimiter">></span>
<span class="inline even last">You Are Here</span>

Open in new window

All the samples I've seen are using some kind of layout that uses and unordered list with list items.

This is how it needs to look:
Home > Link 1 > Link 2 > Link 3 > Link 4 > You Are Here

Open in new window


I've tried some NuGet offerings, MVCBreadCrumb, and MVCSiteMapProvider but couldn't get them to actually work in my project.

Anyone know a quick way to do this?
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

ASKER

I found this and it works somewhat. I just can't get it to format the span's correctly based on the even/odd paradigm.

@Html.ActionLink("Home", "Index", "Home")
@if (ViewContext.RouteData.Values["controller"].ToString() != "Home")
{
    @Html.Raw(" > ")@Html.ActionLink(ViewContext.RouteData.Values["controller"].ToString(), "Index", ViewContext.RouteData.Values["controller"].ToString())
}
@if (ViewContext.RouteData.Values["action"].ToString() != "Index")
{
    @Html.Raw(" > ")@Html.ActionLink(ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString())
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of louisfr
louisfr

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Not using ActionLinks.
Avatar of louisfr
louisfr

They looked like ActionLinks in your previous post.