c# - Create Hyperlinks from controller in asp.net MVC -
i have controller, creates breadcrumbs follows:
software > windows 7 > outlook 2007 the code create is:
viewbag.breadcrumbs = string.join(" > ", cbh.select(i => i.title)); is there straightforward way of making breadcrumbs hyperlinks, point (i.parentid) ie:
software -> forum/index/12 windows 7 -> forum/index/19 outlook 2007 -> forum/index/23 or should loop through cbh , manually build <a href=...> strings, , pass view?
thank you,
mark
your best bet put required items model loop through them.
try this:
model
public class model { public struct breadcrumb { public string title; public string url; } public list<breadcrumb> breadcrumbs { get; set; } } view
@{ int index = 0; } @foreach(var crumb in this.model.breadcrumbs) { <a href="@(crumb.url)" title="@(crumb.title)">@(crumb.title)</a> if(index < this.model.breadcrumbs.count - 1) { <span>></span> } index++; }
Comments
Post a Comment