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

4

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?

Faison answered 26/3, 2014 at 14:52 Comment(1)
@StevenV Ofcourse that has fixed the error.Faison
F
15
@using MvcSiteMapProvider.Web.Html

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

@StevenV

Faison answered 26/3, 2014 at 15:1 Comment(0)
B
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.

Bellabelladonna answered 26/3, 2014 at 15:3 Comment(0)
A
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.

Aerograph answered 26/3, 2014 at 19:42 Comment(0)
G
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
Getraer answered 26/3, 2014 at 15:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.