7

I am using MvcSiteMapProvider MVC5 with my web application and inside of my _Layout.cshtml file I am using:

@if (Html.MvcSiteMap().SiteMap.CurrentNode != Html.MvcSiteMap().SiteMap.RootNode)
    {
        @Html.MvcSiteMap().SiteMapPath()
    }

But the Intellisence is throwing this error:

System.Web.Mvc.HtmlHelper does not contain a definition for MvcSiteMap

Does anyone know how to fix this problem?

user667430
  • 1,487
  • 8
  • 38
  • 73

4 Answers4

15
@using MvcSiteMapProvider.Web.Html

Fixed by adding this to the top of the view as said by

@StevenV

user667430
  • 1,487
  • 8
  • 38
  • 73
4

I think you're missing a using statement. Try adding @using MvcSiteMapProvider.Web.Html to the top of the view.

If you're going to use it often, think about adding the namespace to the <namespaces> section under <system.web.webPages.razor> in the Views\Web.config. That will make it available on all Razor views inside that folder without the need of an using statement on each individual view.

Steven V
  • 16,357
  • 3
  • 63
  • 76
4

The namespaces that @Steven V mentioned are automatically added to the Views\Web.config file during installation of the NuGet package.

<configuration>
  <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>
</configuration>

However, Visual Studio intellisense requires a recompile of the project before it picks them up. There is no need to add a @using MvcSiteMapProvider.Web.Html statement to the view.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
0

You need to install the MvcSiteMap Provider.

You can do this from the Package Manger Console with the following command:

Install-Package MvcSiteMapProvider.MVC5

Then at the top of the razor add:

@using MvcSiteMapProvider
hutchonoid
  • 32,982
  • 15
  • 99
  • 104