MvcSiteMapProvider icon indicating copy to clipboard operation
MvcSiteMapProvider copied to clipboard

MvcSiteMapProvider not working at all

Open vikasNew opened this issue 8 years ago • 4 comments

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.

vikasNew avatar Jun 07 '16 08:06 vikasNew

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.

NightOwl888 avatar Jun 07 '16 09:06 NightOwl888

@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 avatar Jun 08 '16 09:06 vikasNew

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.

vikasNew avatar Jun 08 '16 10:06 vikasNew

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.

NightOwl888 avatar Jun 11 '16 22:06 NightOwl888