Sitemap 3.0 and MVC 3

Jan 16, 2011 at 2:23 PM

in Sitemap 2.3 this code used to work fine with me:

<%= Html.MvcSiteMap().Menu(SiteMap.Provider.FindSiteMapNodeFromKey("Accounting"), true, false, 2)%>

Now I switched for Sitemap 3.0 to use the new routing feature, So I compiled it and used the binary file in my project but now I get the some error when I use the following code:

@Html.MvcSiteMap().Menu(SiteMap.Provider.FindSiteMapNodeFromKey("Home"),true,false,2);

 

the error message is:

 

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Source File: e:\SilverKey\Demo code\Sitemap\Sitemap\Sitemap\Views\Home\Index.cshtml    Line: 

Stack Trace: 

Line 4:  
Line 5:  <h2>Index</h2>
Line 6:  @Html.MvcSiteMap().Menu(SiteMap.Provider.FindSiteMapNodeFromKey("Home"),true,false,2);
[NullReferenceException: Object reference not set to an instance of an object.]
   MvcSiteMapProvider.XElementExtensions.GetAttributeValue(XElement node, String attributeName) +83
   MvcSiteMapProvider.DefaultSiteMapProvider.BuildSiteMap() +567

 

What could be the reason for this error ? 

thanks alot.

Coordinator
Jan 17, 2011 at 6:04 AM

Have you updated your sitemap XML's namespace to reflect version 3 instead of 2?

Jan 18, 2011 at 9:34 AM

I changed it to

<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">

and now it works fine, thanks alot :)