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?
LVL 26
Eddie ShipmanAll-around developerAsked:
Who is Participating?
 
louisfrCommented:
You can add a class to an ActionLink:
@Html.ActionLink(ViewContext.RouteData.Values["controller"].ToString(), "Index", ViewContext.RouteData.Values["controller"].ToString(), new { @class = "even" })
@Html.ActionLink(ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString(), new { @class = "odd" })

Open in new window

0
 
Eddie ShipmanAll-around developerAuthor Commented:
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

0
 
Eddie ShipmanAll-around developerAuthor Commented:
Not using ActionLinks.
0
 
louisfrCommented:
They looked like ActionLinks in your previous post.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.