我希望将面包屑添加到我的网站,但是我不确定如何去做。我已经可以使用以下代码获得一些基本的信息:

<ol class="breadcrumb">
    <li class="active">
        @Html.ActionLink("Home", "Index", "Home")
        @if (ViewContext.RouteData.Values["controller"] != "Home" && ViewContext.RouteData.Values["action"] != "Index")
        {
            @:> @Html.ActionLink(ViewContext.RouteData.Values["controller"].ToString(), "Index", ViewContext.RouteData.Values["controller"].ToString())
        }

        > @ViewBag.SubTitle
    </li>
</ol>

我的问题是,这实际上并没有追踪您的历史,只是向您显示
Home > ControllerName > CurrentItem

例如
Home > Members > Greg Dodd

当您来自成员(member)搜索页面时,此方法效果很好,但是,如果您来自其他页面,则会丢失该历史记录。如何在MVC中使用“历史记录”创建面包屑跟踪?

我想我正在寻找的是这样的:
Home > Controller1 > PreviousItem > ... > CurrentItem

例如
如果您打开一个博客,然后打开一个特定的博客项目,然后单击作者姓名,则面包屑应为:
Home > Blog > SomeBlogTitle > AuthorName

但是,如果您打开了一个作者列表,然后选择了一个特定的作者,您将看到使用相同 Controller 呈现的相同 View ,但面包屑应显示:
Home > Authors > AuthorName

最佳答案

我创建了一个OSS项目来为自己解决问题。我需要对面包屑中的标签进行更多的动态控制:

https://www.nuget.org/packages/MvcBreadCrumbs

或者,在这里贡献:

https://github.com/thelarz/MvcBreadCrumbs

关于c# - 使用Bootstrap的C#MVC网站中的面包屑,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21494075/

10-13 02:32