How to create breadcrumbs using MVC SiteMap provider

Jan 5, 2011 at 12:05 PM

I am totally new to this. Can i have a detail step-by-step procedure to use mvc sitemap provider to create breadcrumbs. I have downloaded the dll and placed it in the bin folder. I have added its reference in the application. Also I have added the <sitemap> tag in the web.config.

 <siteMap defaultProvider="MvcSiteMapProvider" enabled="true">
      <providers>
        <clear />
        <add name="MvcSiteMapProvider"
             type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider"
             siteMapFile="~/Mvc.Sitemap"
             securityTrimmingEnabled="true"
             cacheDuration="5"
             enableLocalization="true"
             scanAssembliesForSiteMapNodes="true"
             excludeAssembliesForScan=""
             includeAssembliesForScan=""
             attributesToIgnore="bling"
             nodeKeyGenerator="MvcSiteMapProvider.DefaultNodeKeyGenerator, MvcSiteMapProvider"
             controllerTypeResolver="MvcSiteMapProvider.DefaultControllerTypeResolver, MvcSiteMapProvider"
             actionMethodParameterResolver="MvcSiteMapProvider.DefaultActionMethodParameterResolver, MvcSiteMapProvider"
             aclModule="MvcSiteMapProvider.DefaultAclModule, MvcSiteMapProvider"
             siteMapNodeUrlResolver="MvcSiteMapProvider.DefaultSiteMapNodeUrlResolver, MvcSiteMapProvider"
             siteMapNodeVisibilityProvider="MvcSiteMapProvider.DefaultSiteMapNodeVisibilityProvider, MvcSiteMapProvider"
             siteMapProviderEventHandler="MvcSiteMapProvider.DefaultSiteMapProviderEventHandler, MvcSiteMapProvider"
         />
      </providers>
    </siteMap>

 

Now i need to create the xml file. Please explain me in detail how to name the xml file and where to create it in the appln? Also how to add the sitemap in the views?

Jan 5, 2011 at 2:06 PM

Try exploring the http://mvcsitemap.codeplex.com/releases/58013/download/190331, it shows a lot of the features available (such as breadcrumbs).

Jan 6, 2011 at 6:05 AM

I created Sitemap.aspx in Shared folder and added mvcSiteMapNodes in Mvc.sitemap.xml. Also added following tags in Site.Master.

                   <ul><li><a href="/Shared/SiteMap">Sitemap</a></li>
                    <li><a href="/sitemap.xml">XML</a></li></ul>

In Sitemap.aspx has:

<h3>Sitemap</h3>

    <%=Html.MvcSiteMap().SiteMap()%>

where MvcSiteMap() gives the following error:

'System.Web.Mvc.HtmlHelper<object>' does not contain a definition for 'MvcSiteMap' and no extension method 'MvcSiteMap' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<object>' could be found (are you missing a using directive or an assembly reference?)'

I have already added a reference to MvcSiteMapProvider.dll.

Please help me on this.

 

Jan 6, 2011 at 7:38 AM

What MVC version are you using?

Have you modified Web.config:

<pages>
   <namespaces>
      ...
      <add namespace="MvcSiteMapProvider.Web.Html" />
   </namespaces>
</pages>
Jan 6, 2011 at 10:19 AM


Thanks a lot. I included the namespace in web.config and the error is gone now. But still I cant find the breadcrumbs in any of my views. I am using ASP.NET MVC 2. Since am a newbie to both mvc and sitemap I might have missed something. Please describe what and how should the master view look like in order to show the breadcrumbs.

Jul 21, 2011 at 10:10 PM

I've done the above corrections, and it still doesn't work. I am using MVC 3.

Someone else in StackOverFlow website said that the MvcSiteMapProvider will not work with strongly typed collections (which is what I'm using in this project).

In another project, I'm not using strongly typed collections and it works fine.

Please let me know if and when I can implement a work-around for this or when you update the dll.

Thanks,

Bill..