maartenba / MvcSiteMapProvider

An ASP.NET MVC SiteMapProvider implementation for the ASP.NET MVC framework.
Microsoft Public License
537 stars 220 forks source link

MvcSiteMapProvider not working at all #443

Open vikasNew opened 8 years ago

vikasNew commented 8 years ago

i have successfully installed MvcSiteMapProviderMVC4 from nuget, but when i add below two lines in my layout page breadcrumbs does not display. only menu display without links.

@Html.MvcSiteMap().Menu() @Html.MvcSiteMap().SiteMapPath()

my project is mixing of web forms and mvc 4.0. Dot Net Framework is 4.0. i am not understanding what i am doing worng. i have tried many times but same issue occurs. but interesting thing is that in new project this work fine.

In my project menu shows without links and breadcrumbs does not display.

NightOwl888 commented 8 years ago

MvcSiteMapProvider consumes MVC routing and also requires a node configuration to define how controller actions are to be nested. Most of the examples show this in XML, but you can define nodes many different ways.

I suggest you go through the article How to Make MvcSiteMapProvider Remember a User's Position to understand exactly how to get it matching.

Since it works in a new project but not in an existing project, most likely you either have misconfigured routes or you haven't accounted for all of the route values that are in your existing application. If you can post your entire routing configuration (including areas) and how your nodes are configured, and a sample of how you want the breadcrumb to look in certain cases I might be able to tell you where to start.

vikasNew commented 8 years ago

@NightOwl888 thanks for your reply, hope it would help me but one thing i want to tell you that new projects where this is working fine has same routes defined.

vikasNew commented 8 years ago

here is my nodes and output.

1. Mvc.sitemap file

screenshot_2

2. Routes

routes.MapRoute( name: "Admin", url: "{section}/{controller}/{action}/{id}", defaults: new { action = "index", id = UrlParameter.Optional }, constraints: new RouteValueDictionary { { "section", "admin" } } );

3. Output screen

screenshot_1

Now you can see that only menus are displaying without any link. breadcrumbs are not appearing at all. please tell me what should i do to display breadcrumbs.

thank you in anticipation.

NightOwl888 commented 8 years ago

The issue is that you haven't accounted for the {section} parameter in your SiteMap. If {section} has nothing to do with the selection of the page, you can force a match on any value using preservedRouteParameters.

<mvcSiteMapNode title="Product List" controller="Product" action="List" preservedRouteParameters="section">

As pointed out in the article How to Make MvcSiteMapProvider Remember a User's Position, you need to manually account for all route values in order to make it match.