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?
@using MvcSiteMapProvider.Web.Html
Fixed by adding this to the top of the view as said by
@StevenV
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.
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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.