Problems with Dynamic Nodes with MVC 3 C#

Apr 10, 2011 at 7:26 PM
Edited Apr 10, 2011 at 7:29 PM

Hi All,

I am truly battling trying to get dynamic urls to display correctly as breadcrumbs in my application. So I decided to download the the MVC Music Store Application and start from scratch.

This was my process.

  • Installed the MVC 3 package from Nuget
  • Changed my sitemap to the following
    <?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="Genre" controller="Store" action="Index">
          <mvcSiteMapNode title="Browse" action="Browse" dynamicNodeProvider="MvcMusicStore.Code.StoreBrowseDynamicNodeProvider, Mvc Music Store">
            <mvcSiteMapNode title="Details" action="Details" dynamicNodeProvider="MvcMusicStore.Code.StoreDetailsDynamicNodeProvider, Mvc Music Store" />
          </mvcSiteMapNode>
        </mvcSiteMapNode>
      </mvcSiteMapNode>
    </mvcSiteMap>
  • Took the following above functions directly from the code folder from the sample app and inserted them into the music store application
  • Inserted the following into my browse view @Html.MvcSiteMap().SiteMap()
  • I keep getting  a Null exception and when I debug I never hit the following MvcMusicStore.Code.StoreDetailsDynamicNodeProvider

 

Your help will be much appreciated. Does anyone maybe have a sample app that I could run and test that got this working with MVC 3?

Coordinator
Apr 20, 2011 at 2:39 PM

This will be fixed with the next release, for now use these instructions:

Registering MvcSiteMapProvider HtmlHelper functions with Razor ViewEngine

In the Web.config file under the Views folder, add the following under the <system.web.webPages.razor> element:

<system.web.webPages.razor>
  <! -- ... -->
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      <! -- ... --> 
      <add namespace="MvcSiteMapProvider.Web.Html" /> 
      <add namespace="MvcSiteMapProvider.Web.Html.Models" /> 
    </namespaces>
  </pages>
</system.web.webPages.razor>
Apr 20, 2011 at 8:44 PM

I ran into a problem like this.

As far as I can remember you fix like so.....

Change the lines like this:

<mvcSiteMapNode title="Browse" action="Browse" dynamicNodeProvider="MvcMusicStore.Code.StoreBrowseDynamicNodeProvider, Mvc Music Store">

To be like this:

<mvcSiteMapNode title="Browse" action="Browse" dynamicNodeProvider="MvcMusicStore.Code.StoreBrowseDynamicNodeProvider, MvcMusicStore">

I.E: remove the spaces

Apr 22, 2011 at 2:48 PM

Thanks guys,

Finally got it working with your suggestions and am excited to use it in future projects.

Thanks,

Tyrone