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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
回答2:
@Chris: something like this:
<%
foreach (var item in ViewData.Get<Breadcrumb[]>())
{
%>
<a href="<%= Server.HtmlEncode(item.Url) %>"><%= item.LinkText %></a> »
<%
}
%>