我这样做的方式是,我使用原始的 mvc 站点地图助手源来渲染面包屑,并将其更改为处理参数(尽管在我的项目中,我们仅显示用于过滤的参数并允许用户单击它们以释放其他过滤参数,下面是节点文本的非常幼稚的实现,只是一个如何完成的示例):
private static string SiteMapText(this MvcSiteMapHtmlHelper helper, SiteMapNode node, string linkCssClass, IDictionary<string, object> htmlAttributes)
{
var extraAttributes = new StringBuilder();
foreach (var attribute in htmlAttributes)
{
extraAttributes.Append(" " + attribute.Key + "=\"" + attribute.Value + "\"");
}
string spanHtml;
var paramDictionary = helper.HtmlHelper.ViewContext.RequestContext.HttpContext.Request.Params.ToDictionary();
var queryParams = paramDictionary.Select(x => string.Format("{0}:{1}", x.Key, x.Value));
// here you add request parameters
var title = helper.HtmlHelper.Encode(string.Format("{0} ({1})", node.Title, string.Join(";", queryParams)));
if (!string.IsNullOrEmpty(linkCssClass))
{
spanHtml = string.Format("<span><span class=\"{0}\"{1}>{2}</span>", linkCssClass, extraAttributes, title);
}
else
{
spanHtml = string.Format("<span><span{1}>{0}</span>", title, extraAttributes);
}
return spanHtml;
}
以同样的方式,您可以调整 SiteMapLink 方法,以包含当前节点的请求参数。