MVC Sitemap Provider tutorial 2 – Breadcrumbs

Once you’ve got your sitemap correctly configured and setup, you will be looking to use some of the features of a Sitemap – for example, breadcrumbs. In this post we will start with an empty MVC3 project, and add the asp.net sitemap provider, a few controller actions and corresponding views, and we will have the provider produce some breadcrumbs for us.

Setup

Lets start from an Empty MVC3 project. Fire up Visual Studio. Create a new Asp.Net MVC3 Web application. I’m going to call mine SitemapDemo:

Create new MVC3 project

For the sake of this demonstration, I have selected an empty template and have chosen Razor as my view engine.

Now before we go any further, lets go ahead and install the NuGet package.  Select View > Other Windows and then select “Package Manager Console”:

Package Manager Console Location VS2010

This will then dock the Package Manager Console somewhere into your view. In order to add the Asp.net MVC sitemap provider to the current project, we need to enter the following command into the Package Manager Console, and hit enter:

PM> Install-Package MvcSiteMapProvider

This command will then download the necessary files (dlls, cshtml files) and add them into your MVC project. This could take a few minutes depending on your connection. If this has been successful, your Package Manager Console should give you an output similar to the following:

PM> Install-Package MvcSiteMapProvider
Successfully installed 'MvcSiteMapProvider 3.1.0.0'.
Successfully added 'MvcSiteMapProvider 3.1.0.0' to SitemapDemo.

PM>

Now lets take a look at what exactly the NuGet package manager has added to our project:

  • SitemapDemo > References > MvcSiteMapProvider – This is the reference to the MvcSiteMapProvider dll
  • SitemapDemo > Mvc.sitemap – This file will be used to describe our MVC3 website in XML nodes
  • SitemapDemo > Views > Shared > DisplayTemplates > MenuHelperModel.cshtml
  • SitemapDemo > Views > Shared > DisplayTemplates > SiteMapHelperModel.cshtml
  • SitemapDemo > Views > Shared > DisplayTemplates > SiteMapNodeModel.cshtml
  • SitemapDemo > Views > Shared > DisplayTemplates > SiteMapNodeModelList.cshtml
  • SitemapDemo > Views > Shared > DisplayTemplates > SiteMapPathHelperModel.cshtml
  • SitemapDemo > Views > Shared > DisplayTemplates > SiteMapTitleHelperModel.cshtml

As we’re using Razor as our view engine, we can go ahead and delete the asax files that have been added to the SitemapDemo > Views > Shared > DisplayTemplates folder. Here’s how your solution should now look:

Sitemapdemo Solution Explorer

Now that’s the install over. Let’s add a half decent set of controller actions and views to the site before we go on to playing with the SiteMapProvider. The point of this is to capture the kind of structure that you would find in a typical website.

Important

The MVC Sitemap provider will fail silently in some fashion if we try to force it to work with controller actions that either don’t exist or that point to non existent views. This is why we are doing this stage first.

All sites have a homepage, so lets add this first. Right click on your Controllers folder, and add a controller called “HomeController”. Lets leave the scaffolding options blank:

HomeController-Add Blank

Once your controller is created and open, right click inside the Index action and select “Add View…”

Home Index Add View

In the Add View dialogue that pops up, just go a head hit add. Nothing will need changing.  Now lets change the text inside the created page’s h2 tag on the page – something like “Index – this is the home page” will do.

And now lets add another controller in the same way that we added the HomeController. Let’s call it NewsController. Update the newly created news controller to contain an additional action result called “Sports”:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SitemapDemo.Controllers
{
    public class NewsController : Controller
    {
        //
        // GET: /News/

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /News/Sports/
        public ActionResult Sports()
        {
            return View();
        }

    }
}

Now, lets add a view for each of our newly created NewsController actions. Lets do this in the same way that we added the view for the home page – by right clicking within the body of each controller action. Again, we can simply leave all of the defaults in the “Add View” dialogue and just hit “Add” for both views.

Now edit the h2 tag on the News Index cshtml file to read “News Index”. Lets also edit the h2 tag on the News Sports cshtml file to read “Sports News”.

Let’s now add one more Controller for illustration – AboutController. Once created, you can leave the controller unchanged, and can add a view for the Index controller action. This time, lets change the h2 to tags to read “About Page”.

As we have now added 4 pages to our website, it’s now worth just testing them out before we start integrating the Site Map Provider. Hit the debug button – below are screen shots and their corresponding URLs:

localhost:xxxx

SitemapDemo Index

localhost:xxxx/News

SitemapDemo News Index

localhost:xxxx/News/Sports

SitemapDemo News Sports

localhost:xxxx/About

SitemapDemo About Index

Ok, so we’ve now got a small site with a little bit of a structure. Lets represent that structure in an easy diagram:

SitemapDemo Sitemap Diagram

Visualising our layout like this will really help us describe our site’s structure in our Mvc.sitemap file correctly. Our Index page is our wrapper for the entire site as it is the page that sits in the root, and is the first port of call into the site.

Now lets get into configuring our Sitemap. Lets start by editing our Mvc.sitemap file, which is in the root of our project. This file contains all of the xml nodes needed to represent your controller and action combinations.

MVC Sitemap xml file vs

Edit your Mvc.Sitemap file so that it is the same as the listing below:

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
  <mvcSiteMapNode title="Home" controller="Home" action="Index">
    <mvcSiteMapNode title="News" controller="News" action="Index">
      <mvcSiteMapNode title="Sports News" controller="News" action="Sports"/>
    </mvcSiteMapNode>
    <mvcSiteMapNode title="About" controller="About" action="Index"/>
  </mvcSiteMapNode>
</mvcSiteMap>

We have now represented our website structure / workflow in the MVC.Sitemap file. A classic “gotcha” here is forgetting that your entire site is wrapped in a node that represents your homepage. Your sitemap file must contain this node – after all, your website’s homepage is the page that the client sees as the root of everything. So even though the Index action is actually at yourwebsite/Index, the client will typically see it just as yourwebsite/. The rest of the structure should make sense when compared to the website navigation diagram, earlier in this post.

Adding Navigation

Now that we’ve got some controllers and actions setup, and our site structure described properly in our Mvc.Sitemap file, lets add some navigation to all pages.

Open up your _Layout.cshtml partial, located in the Views/Shared folder. Update the listing so that the code between the body tags looks like this:

<body>
    @Html.MvcSiteMap().Menu(false, true, true)
    @RenderBody()
</body>

We are now calling the MvcSiteMap library and telling it to output the website’s navigation on every page. The parameters specified mean that:

  • We don’t want it to start from the current node (changing this to true will break it!)
  • We want the starting node to appear in child level
  • We want to show the starting node. Setting this to false will hide the parental “Home” node
And now if we run our application, we should see the navigation laid out on every page, complete with links:
Index with navigation

News with navigation

Editing the navigation appearance

So now we’ve managed to output a simple navigation onto all pages of our website. If you want to change any styling, or how the navigation is displayed, simply alter the code in Views/Shared/DisplayTemplates/MenuHelperModel.cshtml. Lets make a simple change and add an inline style to change our bullet points from circles to squares:

<ul>
    @foreach (var node in Model.Nodes) {
        <li style="list-style-type:square;">@Html.DisplayFor(m => node)
            @if (node.Children.Any()) {
                @Html.DisplayFor(m => node.Children)
            }
        </li>
    }
</ul>

You can now hit refresh in your browser without needing to re-compile. Your News index page should now look like this:

News Index Square Bullets

Breadcrumbs

We can add breadcrumbs in a similarly easy fashion. Let’s open up our _Layout.cshtml partial and edit the listing:

<body>
    @Html.MvcSiteMap().Menu(false, true, true)
    <p>Start of Breadcrumbs:</p>
    @Html.MvcSiteMap().SiteMapPath()
    @RenderBody()
</body>

Now all pages on our site will have a handy set of breadcrumb links:

News Breadcrumbs MvcSitemap

Sportsnews breadcrumbs MVCSitemap

Similarly, if we want to customise the presentation of our breadcrumbs, we need to change the Views/Shared/DisplayTemplates/SiteMapPathHelperModel.cshtml file.

Dynamic URLs / Parametered URLs

Every real site will need to employ a dynamic / Parametered URL at some point. Incorporating a dynamic URL into the MVC Sitemap is straightforward when you know how. Lets start by adding a new action to the NewsController:

        //
        //GET: News/Article/x
        public ActionResult Article(int id)
        {
            ViewBag.id = id;
            return View();
        }

Now lets add a view – right click anywhere within the new action and select “Add View…”. Again, just hit Add – we don’t need to change any of the options. Now update the newly created Article.cshtml file with the following:

@{
    ViewBag.Title = "Article";
}

<h2>Viewing Article @ViewBag.id</h2>

Now lets browse to localhost:xxxx/News/Article/1234:

News Article 1234 mvcsitemap

Note that this new page does not appear anywhere in our sitemap, and that the breadcrumbs are totally empty.

In order to add the page into our navigation, we must first decide where it needs to go. I’d like this page to sit underneath the News section. So lets edit our Mvc.Sitemap file and add a Key attribute to the “News” node. This is simply to give it a unique identifier:

<mvcSiteMapNode title="News" controller="News" action="Index" key="News">

Now we need to decorate our controller action with some attributes that tell it where to insert the action in the site’s structure. Update your Article action in your News controller:

        //
        //GET: News/Article/x
        [MvcSiteMapNode(Title = "Article", ParentKey = "News")]
        public ActionResult Article(int id)
        {
            ViewBag.id = id;
            return View();
        }

Now lets compile and browse to localhost:xxxx/News/Article/1234:

Article Dynamic MVCSitemap

And we now have Breadcrumbs and navigation for our new page, despite it having a dynamic URL!

Download the Solution

You can download the complete solution here

Recommended Reading:

Pro ASP.NET MVC 3 Framework

About these ads

65 comments

  1. Pingback: MVC Sitemap Provider tutorial and examples « Ed Spencer's Blog

  2. Thanks for the tutorial.
    I’ve just started using Mvc Sitemap provider and I have some questions:

    1. When using dynamic url, like you do for your article, how can you display the title of the Article in the breadcrumb ? ie : not “Home > News > Article” but “Home > News > “My article title” (some thing like dynamic titles)

    2. Lets say that in your news controller you would have something like a SubArticles actions that takes 2 urls as parameters SubArticle(string articleUrl, string subArticleUrl). How can I achieve something like “Home > Article > “My article url” > “My sub article title”

    Any help you be appreciated :)
    Thanks,
    Mihai

    • I know you can do it by hacking the SiteMapPathHelperModel.cshtml, but it’s not pretty
      Something like
      @if (node.Title == “Article”)
      {
      @model.title
      }
      This code is untested, but we have a similar block in a huge project.

      A better way would be if you could set the title of the node dynamically in the controller. I’ll take a look around and see if this is possible

      And your second question would involve a simialr approach. Something like this in the SIteMapPathHelperModel.cshtml file:

      @if (node.Title == “Article”)
      {
      @Request.QueryString[“articleTitle”] > @Request.QueryString[“articleSubTitle”]
      }

      • Thanks for t and it works fine
        the reply. inthe end I did something else: I created a custom attribute and OnActionExecuting I took the url and created my breacrum data which I then added to the view bag.

  3. Hi ,
    I used site map provider it was working fine for the calls that allowed the page to be posted back and call an action method of an controller. But when any action is called using as Ajax call of Jquery and particular view is rendered the site maps doesnt updates accordingly though i have made the entry of that action in the XMl file. Please update me on this.

    • Before I can answer this question, I need to understand how you are loading the content.

      Are you loading an entire page? As in the Ajax is calling a controller action that returns a View?

      If so, what are you doing with the HTML from the view? Is it being rendered onto a section of the page?

      Is a redirect happening?

      If the HTML is being rendered onto the current page, then there is no way that the breadcrumbs will update themselves, unless the breadcrumbs are in the HTML of the newly generated view. Remember that as soon as the HTML is with the client, it cannot be changed unless some AJAX call is made to specifically update a particular element.

      • Hi Ed I am having View and inside that i am having JQuery Tab on each tab click i am loading the Partial view from the controller
        But while doing this i need to update the breadcrumbs also but MVCSitemapprovider is not doing that.please help me

  4. I’d love to see an example of how to modify the DisplayTemplates to indicate the current page on the menu.

    For example, if you have a menu with two nodes, Home and About, and you’re currently on the About page, indicate this in the menu by underlining the About title.

  5. Hi, Have you used roles with the mvcsitemap provider. I have a 2 level menu in my MVC Site.
    It works well…but the moment I set securitytrimming to “true”, each page takes a long time to render.

    • Are you running in debug? I understand that the current version of the MVC sitemap provider kicks out masses of errors when running in debug (view the output when starting a debug session). You won’t notice the impact if you’ve got lots of ram – but it would definitely be worth trying it in release mode to see if its any quicker.

  6. How can i preserve the route data for various nodes.

    Let say if i go to URL http://localhost:55555/Home/Person/12 the breadcrumb looks like this on the Person page

    Home > Person

    But as soon as I navigate further into the page, say “Contact”, the breadcrumb looks like this:

    Home > Person > Contact

    But if I try to navigate back to Person page by clicking Person node, none of the url parameters are maintained (e.g. instead of going to http://localhost:55555/Home/Person/12, it goes to http://localhost:55555/Home/Person).

    My sitemap looks something like

    I have also tried preservedRouteParameters but it doesn’t work

    Plz tell me how can i preserve the route data for various nodes in the breadcrumb.

    Cheers

    • Thanks Jules

      hmmmm not too sure at the moment. You could have an xml field in the database and have the entire file there, but I’m not sure how you would specify that to be the sitemap file.

      Its a very interesting point though. In a load balanced setup where you have plenty of web servers, it would be nice if you could have just one sitemap file, rather than one on each web server. I’ll take a look into it

  7. Really good example shame it has taken me 2 days to find it (incredibly frustrating as all I want is to stick a few menus on screen :)), im upgrading an old asp app and previously used sitemap but that was years ago, your tutorial is clear specific and exactloy what I was looking for, im more midle tier backend and cant remeber how to do the js or css to have the menus drop down dont supose yo could provide an example :)

  8. Very helpful, thank you. Please don’t forget to update with answers for Mihai question about dynamic url and NickS question about showing current page on the menu.

  9. Hi Edward,
    I would like to know if there is a way to set the node title dynamically from the controller. What i need to do is to set the node title with infomration about the parameters that i receive in the controller, rather than using a static node title.

    Any hint will be highly appreciated.
    Paola

  10. Hello Ed, I am trying to display a different look and feel if the menu item is currently active. I tried to use node.IsInCurrentPath as a flag, but the first node is always returning true. Below is my code on menuhelperModel.cshtml

    @model MvcSiteMapProvider.Web.Html.Models.MenuHelperModel
    @using System.Web.Mvc.Html
    @using MvcSiteMapProvider.Web.Html.Models

    @foreach (var node in Model.Nodes)
    {
    if (node.IsInCurrentPath)
    {
    @Html.DisplayFor(m => node)
    }
    else
    {
    @Html.DisplayFor(m => node)
    }
    }

    Is there a different flag I can use?

  11. Also my controller has the same action either as HttpGet and HttpPost, and i would like to add a breadcrumb for both of them. I have tried to do something like:

    [HttpGet]
    [MvcSiteMapNode(Title = “MyControllerActionGet”, ParentKey = “Home”, Key = “MyControllerActionGet”)]
    public ActionResult MyControllerAction(string viewResultType)
    {

    }

    [HttpPost]
    [MvcSiteMapNode(Title = “MyControllerActionPost”, ParentKey = “MyControllerActionGet”, Key = “MyControllerActionPost”)]
    public ActionResult MyControllerActionPost(string viewResultType, LiquidacionConsulta model)
    {
    ….
    }

    But this is not always working properly. Is there a way to accomplish this?
    Thanks in advance,

  12. Hi,

    I’m using ASP.NET MVC 2.0 and MVCSitemap2.0

    My BreadCrumb is displaying like in a page

    DashBoard>>HotelPolicy>>ChildPolicy View”

    Here HotelPricing has a method “Create” and accepts parameter HotelCode , the problem here is i unable to pass hotelcode for Hotelpricing Create method.when i click on HotelPolicy Link that should Navigate to http;//localhost:2287/Policy/HotelPolicy/Create/HTL9834.But when i click on HotelPolicy is redirecting to http;//localhost:2287/Policy/HotelPolicy/Create/. Here I should pass the parameters to Create method of HotelPolicy

    MY complete APP structure is:

    web.config:

    web.sitemap:

    Note: I did only Above thing in my application and i didnot touch controller

  13. Hi Ed – great blog!!

    Ive just implemented the site map provider. I am trying to get the security trimming to work. I have my action method attributed with [Authorize] but the menu node is still showing on the home page before the user log on. Is there something I am missing? Thanks

    • Hi Greg,

      I’m not too sure about the security trimming, but you could always modify the menu display templates to check for an authorised user before rendering any nodes.

      On any sites I’ve used the sitemap provider we’ve literally not rendered the menu at all on non authenticated pages. So the sites have been more like private enterprise applications.

      I’d be keen to know if you got anywhere with the security trimming.

      If you are totally stuck, it might be worth messaging the guy that wrote the plugin over on github https://github.com/maartenba/MvcSiteMapProvider

      Good luck

  14. Hi,

    It’s a wonder why anyone hasn’t asked yet, but isn’t the tree sitemap supposed to be collapsible? No matter what I edit, I can’t only set a maximum node depth to appear wherein ALL the nodes appear. All I get is a tree sitemap that’s fully expanded. What if I’m at Home > Company Information and I want Company Information AND ONLY Company Information to have its nodes expanded?

    i.e.

    Home
    – Products
    – Company Information
    – Company Profile
    – Corporate Responsibility
    – Mission and Vision
    – Contact Us
    – Careers

    I don’t want all my level 1 nodes all expanding FFS.

    • Kyle, that’s down to the presentation.

      Just change your cshtml files to spit out html that works with some css to collapse nodes accordingly.

      This is exactly what we do on several of our sites that use this.

      Remember the Sitemap provider basically gives you nods, and turns those nodes into html. You can customise that html under certain conditions.

      E.g.


      @if(node.Description == "home")
      <li>Home Node</li>
      else
      <li class="collapsed"> Collapsed Node</li>

      And then your CSS obviously has something in it to deal with li.collapsed.

  15. Hello, Edward.

    Do you know how to choose various display templates for nodes? I want to show various node styles in various menus. But Html.MvcSiteMap().Menu(), Html.MvcSiteMap().SiteMapPath() and so forth functions of Html.MvcSiteMap() can receive templates for their own structure only, not for nodes. And all of these functions use single SiteMapNodeModel.cshtml template. How to choose another node template? Is there really only one way – to rewrite the single SiteMapNodeModel.cshtml template?

    • Hi Hugo,

      When you call @Html.MvcSiteMap().Menu(false, true, true) in your _layout.cshtml page or similar, I believe that there is an overload for this call that will let you specify the template file name.

  16. Awesome. Here is some jquery script I dropped on my partial view to append parameters to each breadcrumb node.

    //Append the ageny as a query string aparameter to all the breadcrumb links. The MVCSiteMapProvider does not include these.
    var currentAgency = $.trim(window.sessionStorage.getItem(“currentAgency”));
    var breadCrumb = $(“.divBreadCrumb”);
    $(breadCrumb).children(‘a’).each(function () {
    $(this).attr(‘href’, $(this).attr(‘href’).trim() + “?yz=” + obfuscateAgencyNumber(currentAgency));
    });

  17. I have the same question as HARI which does not look like it was ever answered. I need to include route values or querystring parameters on the urls in the breadcrumbs. Updating the URL property or adding to the route values in the SiteMapPathHelperModel has absolutely no effect (same as changing the title etc), so basically updates to the properties of the node in this file have no effect, why is that?

  18. I’m getting sick of MvcSiteMapProvider. It seems that everytime I get the latest version, the stupid thing breaks and I have to spend hours trying to figure out why, tweaking my code to make sure it is just right.

      • There are already plenty of comments expressing similar sentiments. I admit that I wrote that comment in a moment of frustration, but I stand by it nonetheless. I’m using SiteMapProvider for my menus until JQueryUI finally releases theirs to production, then I’ll be switching over.

      • It’s understandable. We’ve just got it working and left it. We don’t have the budget to spend time fixing previously working areas of the application. We only update something if we feel there is a benefit that we will get from the newer version

  19. Thanks a lot for the tutorials. They are very clear.
    One point. When you write ” ..can go ahead and delete the asax files” I think you mean ascx.

  20. Edward, awesome tut, thank you for it! Quick question, it’s only displaying three levels for me though: Home > Child 1 > Child 2. For example:

    If I’m on the “Blah2″ page inside of “Demo1″, it only shows Home > Community > Demo1, where I’d like it to then say > Blah2. Does that make sense?

    • It didn’t display my code. Lemme try again:

      mvcSiteMapNode title=”Home” action=”Index”
      mvcSiteMapNode title=”Community” action=”Index”
      mvcSiteMapNode title=”Demo1″ action=”Demo1″
      mvcSiteMapNode title=”Blah2″ action=”Blah2″/>
      /mvcSiteMapNode
      /mvcSiteMapNode
      /mvcSiteMapNode

  21. I could make the breadcrumb appear for the Actions in my controller by adding [MvcSiteMapNode(Title=”Search”, ParentKey = “Benefits”)], [MvcSiteMapNode(Title=”Manage”, ParentKey = “Benefits”)] etc.,. But this will add sub menu nodes under Menu though it was not required. How can I Make the bredcrub appear for all actions in my controller without adding a node into the Main menu?

  22. Hi,
    I am using mvc.sitemap file in my mvc project for bread crumbs,this was working fine unless i added authorization in

    project, i have implemented LogonAuthorize class from AuthorizeAttribute class and overrided its OnAuthorization

    method and registered that into GlobalFilterCollection but due to that bread crumbs are not displayed on any pages not sure why?,rest of things are working fine with authorization except bread crumbs.
    Can you please help me out?

  23. I have been looking around but I didn’t find an answer for my problem.

    I would like a menu like this :
    1.Home
    2.Admnistration (Not clickable)
    •Personnel
    •Holiday

    When I click the Personnel-item I would like to show the following :
    1.Home
    2.Admnistration
    •Personnel
    •Create New
    (So no longer displayig the “Holiday” and adding the “Create New”)

    When I click the Home-item, I go back to the index-page showing the first menu.
    Clicking the Holiday-item would show a menu like this:
    1.Home
    2.Admnistration
    •Holidays
    •Create New

  24. I am looking for a way to make end-user specified menus/site paths. In fact, there is an application (in PHP, damnit) that does exactly what I am trying to do here http://www.bigace.de/demo.html (administration site v3, Pages > Administration) – make a drag and drop tree menu entry system for my site that controls both the site map path and main menu.

    I have used ASP.NET sitemaps files in the past and it turned out to be a horribly bad idea for a site with end-user created pages because I literally had every page defined in 3 different places, but then, I never looked into making a site map provider as you have.

    I know you touched on this in another question, but assuming I am not afraid to get my hands dirty myself, what specific extensibility point should I exploit to make a database-driven xml file work with your MvcSiteMapProvider?

  25. I have a Home controller and a Business controller. The business controller has a few action methods on it: Search, Create, Update, Delete. From the Search view I can have a link to the Create view.

    On my home page i have a link that takes me to the Search and Create actions on the Business controller.

    I want the bread crumb to look like the following when Create is accessed from the home page:
    Home > Create

    …and i want it to look like the following when Create is accessed from the Search page:
    Home > Business > Create.

    For the same controller/action method combo, can we achieve the effect i want with MvcSiteMapProvider?

    Many thanks!

  26. Many thanks for the awesome step by step instruction. One thing I like to ask is, how do I get rid of the “>” symbol between each page in the breadcrumbs? Inside of the MenuHelperModel.cshtml UL and both LI tag, I already specified style=”list-style-type:none;” but for some reason, it still show the “>” symbol. Any help is much appreciated.

  27. Pingback: Styling MVC Sitemap Provider with CSS | Programming Tutorial Blog

  28. Ed,

    I first came here seeking your advice, and now I have made a major contribution to the MvcSiteMapProvider by refactoring its design into what is now v4. Honestly, I probably wouldn’t have bothered with it at all if it weren’t for your tutorial.

    I added links to this blog post today from the GitHub site, but setting up v4 is different than what is described here and it would be great if you could do a post or 2 on the new version.

    Thanks,
    NightOwl888

    • Hello !

      First, great work on mvcsitemapprovider, this is quite a good project. There’s still one problem for me, which is, i think, really important :

      Is there an easy way to keep route values?

      I have some results pages, that takes a model, a page number, a page size etc.. in input. I need the BreadCrumb to build a link with the parameters in the URL. The preservedRouteParameters doesn’t work for me.

      Thank you!

      • @Julien

        There are 2 ways that are practical to make MvcSiteMapProvider work

        1) Add every potential route value as a new node
        2) Use preservedRouteParameters to force multiple requests to match a single node

        For a page number and page size, it generally makes more sense to use preservedRouteParameters in combination with SiteMapTitleAttribute to match a single node. Do keep in mind this will make the Menu and SiteMap HTML helpers function incorrectly – you can usually fix this by using visibility providers to make the multi-match nodes invisible on the Menu and/or SiteMap.

        I have written a blog post that goes into some depth on this topic: http://www.shiningtreasures.com/post/2013/09/02/how-to-make-mvcsitemapprovider-remember-a-user-position

  29. Pingback: Lindermann's Blog | MvcSiteMapProvider

  30. Pingback: Getting started with MvcSiteMapProvider with ASP.NET MVC | a developer's notes - a semi-technical web development BLOG

  31. what are configurations to add in two web.config files .iam not installing packages direclty to solutions but i added references of that dlls.. it is not working ..it is showing error as sitemappath is not initialized


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s