Has anyone experienced an error described in the image below where the HtmlHelper in razor view is not recognizing Sitecore when I try to specify a placeholder?
Thanks for your help!
Has anyone experienced an error described in the image below where the HtmlHelper in razor view is not recognizing Sitecore when I try to specify a placeholder?
Thanks for your help!
There's a web.config
that has Sitecore references that should exist in the /Views
that is probably not right.
This can be a common occurrence if using a new .NET MVC Project in Visual Studio and it accidently overwrites the Sitecore version.
You can grab the web.config from the Sitecore Vanilla Zip file to compare.
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Sitecore.Mvc" />
<add namespace="Sitecore.Mvc.Presentation" />
<add namespace="System.Web.Optimization" />
</namespaces>
</pages>
</system.web.webPages.razor>
@using Sitecore.Mvc
in the top of your views - that's more of a hassle though.
– Søren Kruse
Oct 5 '16 at 9:01
I think you are missing Sitecore from your Views web.config. You web.config in the /views folder should look like this
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Sitecore.Mvc" />
<add namespace="Sitecore.Mvc.Presentation" />
<add namespace="System.Web.Optimization" />
</namespaces>
</pages>
</system.web.webPages.razor>
I also encountered the same thing. I grabbed the web.config from the habitat demo solution, one of the web.config from the views there and it works fine.
Here's the full web.config.
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor"
type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host"
type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
requirePermission="false" />
<section name="pages"
type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host
factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="Sitecore.Mvc" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="BlockViewHandler" />
<add name="BlockViewHandler" path="*.cshtml" verb="*" preCondition="integratedMode"
type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
And a screenshot: