Create breadcrumbs Path in asp.net MVC

天大地大妈咪最大 提交于 2019-12-12 11:17:21

问题


I'm trying to create a breadcrumbs that includes pages viewed by user, like the example:

Home -> Products -> Smartphones -> .....

Does anyone know how to do that in asp.net mvc 3 with razor view engine ? Or where i can find a good tutorial ?


回答1:


There is an open source project called MvcSiteMapProvider that I have been contributing to that makes this fairly easy. The project is available on NuGet.

Basically, you configure an sitemap with all of your pages. The sitemap can be configured in XML, code, or from another data source. The sitemap is then cached and shared between users. When a user navigates to a URL that is configured in the sitemap (either as a URL or as a dictionary of route values), it will use the relative position in the map to determine how to build breadcrumbs back to your home page.

There is a walk-through of installing and using its features here: MvcSiteMapProvider 4.0 - A Test Drive




回答2:


Have you seen the open-source solution MvcBreadCrumbs? There's a couple of ways to accomplish it with this Nuget package. You can use attributes on controller methods like this:

[BreadCrumb(Label="Widget")]
public ActionResult ...

or optionally add a static method call to override the label if it's data dependent:

[BreadCrumb(Label="Widget")]
public ActionResult Get(int id)
{
    [make db call]
    BreadCrumb.SetLabel(db.ItemDescription);
    return view(dbModel);
}


来源:https://stackoverflow.com/questions/18402684/create-breadcrumbs-path-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!