I know you could make a helper pretty easily given the data. So, if possible, please only submit answers that also include getting the data.
+9
A:
We are using an action filter for this.
...
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var controller = (Controller) filterContext.Controller;
Breadcrumb[] breadcrumbs = _breadcrumbManager.PushBreadcrumb(_breadcrumbLinkText);
controller.ViewData.Add(breadcrumbs);
}
before you mention it, I too have a distaste for service location in the filter attributes - but we are left with few options. IBreadcrumbManager looks like this:
public interface IBreadcrumbManager
{
Breadcrumb[] PushBreadcrumb(string linkText);
}
The implementation puts Breadcrumb objects into the Session. The Url is HttpContext.Current.Request.RawUrl
Matt Hinze
2008-09-15 22:32:19
Is the implementation of IBreadcrumbManager somewhere we can look at? Where does _breakcrumbLinkText come from?
flipdoubt
2009-09-25 21:11:38
could you show a more detailed example of this solution to breadcrumb helper? Do you have any test solution you could share maybe? I don't really get it with the interface _breadcrumbManager/IBreadcrumbManager..
QuBaR
2009-11-29 15:40:47
A:
How would you go about displaying the breadcrumbs in a View?
Chris Pietschmann
2008-09-20 05:48:13
+1
A:
@Chris: something like this:
<%
foreach (var item in ViewData.Get<Breadcrumb[]>())
{
%>
<a href="<%= Server.HtmlEncode(item.Url) %>"><%= item.LinkText %></a> »
<%
}
%>
Matt Hinze
2008-09-21 04:56:12
A:
Matt,
Would you be so kind to show a bit more of your suggested implementation, it intrigues and confuses me all at the same time ;)
For example, where do you instantiate the _breadcrumbManager, and what does it do internally?
Regards, avsomeren
avsomeren
2009-09-12 07:25:06