“System.Web.Webpages.Html。Htmlhelper'不包含'Sitecore'的定义

时间:2022-01-13 16:53:17

I'm getting this error in Visual Studio, when I use @Html.Sitecore:

我在Visual Studio中得到这个错误,当我使用@Html.Sitecore:

'System.Web.Webpages.Html.Htmlhelper' does not contain a definition for 'Sitecore' and the best extension methods overload 'Sitecore.Mvc.HtmlHelperExtensions.Sitecore(System.Web.Mvc.HtmlHelper)' has some invalid arguments.`

“System.Web.Webpages.Html。Htmlhelper'不包含'Sitecore'的定义,最好的扩展方法重载'Sitecore. mvc . htmlhelperextensions.sitecore (System.Web.Mvc.HtmlHelper)'有一些无效的争论。

However, once deployed it does run without any problems.

但是,一旦部署,它运行时没有任何问题。

I'm using Sitecore 7.2 with MVC 5.1.

我使用的是Sitecore 7.2和MVC 5.1。

“System.Web.Webpages.Html。Htmlhelper'不包含'Sitecore'的定义

Articles that I've read that deal with similar error messages, talk about the system.web.webPages.razor section of the Views folder web.config file. This is how it appears in my solution.

我读过的关于处理类似错误消息的文章,可以谈谈system.web.webPages。浏览文件夹的剃刀部分。配置文件。这就是我的解。

<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.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" />
  </namespaces>
</pages>

Originally I thought I'd just need to restart VS, but that didn't work. Does anyone have any suggestions.

最初我以为我只需要重启VS,但那没用。有人有什么建议吗?

EDIT This is the standard Sitecore 7.2 installation, and so has the following binding redirects:

这是标准的Sitecore 7.2安装,因此有以下绑定重定向:

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" xmlns="urn:schemas-microsoft-com:asm.v1"/>
    <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.1.0.0" xmlns="urn:schemas-microsoft-com:asm.v1"/>
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" xmlns="urn:schemas-microsoft-com:asm.v1"/>
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" xmlns="urn:schemas-microsoft-com:asm.v1"/>
  </dependentAssembly>

Also when looking at the output from visual studio there is an additional error that I didn't spot before:

另外,在查看visual studio的输出时,还有一个我以前没有注意到的错误:

Instance argument: cannot convert from 'System.Web.WebPages.Html.HtmlHelper' to 'System.Web.Mvc.HtmlHelper'

实例参数:不能从' system . web . web . web . html转换。HtmlHelper”“System.Web.Mvc.HtmlHelper”

EDIT 2

编辑2

I no longer think this is a Sitecore MVC issue. I get a similar error with @Html.ActionLink("xxx", "xxx"). Other people have seen this issue in VS2012, but I'm using 2013.

我不再认为这是Sitecore MVC的问题。@Html也有类似的错误。ActionLink(“xxx”、“xxx”)。其他人在2012年的VS2012中看到了这个问题,但我用的是2013年。

EDIT 3

编辑3

There are now quite a few answers to this question. I recommend trying each of them as it seems there are numerous reasons this error might occur.

这个问题现在有不少答案。我建议每个人都尝试一下,因为似乎有很多原因导致这个错误。

8 个解决方案

#1


11  

I have the same problem a while ago. We found out that we are missing the web.config inside /views folder. we copy a web.config from my other projects' /views and it solved the issue.

我刚才也有同样的问题。我们发现我们错过了网络。内部配置文件夹/视图。我们复制一个网络。从我的其他项目/视图配置,它解决了问题。

#2


9  

Try This, then try to restart visual studio.

尝试此操作,然后尝试重新启动visual studio。

<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="Sitecore.Mvc" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

You forgot to add <add namespace="Sitecore.Mvc" /> so that intellisense can pick it up in VS.

您忘记添加 ,这样智能感知可以在VS中获取。

#3


4  

I have now resolved this issue. I simply had to install Update 2 of Visual Studio 2013. How frustrating.

我现在已经解决了这个问题。我只需要安装Visual Studio 2013的更新2。多么令人沮丧。

Thanks to StriplingWarrior and Ahmed Okour for your useful advice.

感谢StriplingWarrior和艾哈迈德·奥库尔提供的有益建议。

#4


2  

I have used the below line at the top and the issue has been resolved.

我已经在顶部使用了下面一行,问题已经解决。

@inherits System.Web.Mvc.WebViewPage

#5


1  

You say you're using MVC 5, but you're referencing version 3 in the code you provided. Here's what mine says:

您说您正在使用MVC 5,但是您在提供的代码中引用了version 3。这就是我说:

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Try checking through your entire web.config file (or all the web.config files if you have multiple Areas) and making sure that all the versions are set right. For MVC 5, System.Web.WebPages should be on version 2 and System.Web.WebPages.Razor should be on version 3.

试着检查你的整个网络。配置文件(或所有web文件)。配置文件(如果您有多个区域)并确保所有版本都设置正确。为MVC 5,包含。WebPages应该在版本2和System.Web.WebPages上。Razor应该在第三版。

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

...

  <assemblies>
    <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>

#6


0  

Sometimes its the silly things. Check you're not doing something like

有时是愚蠢的事情。检查你没有做类似的事情

@Html.Sitecore("placeholdername")   // no method

or

@Html.Sitcore.Placeholder("placeholdername") // Missing parenthesis

when you should be doing

当你应该做的时候。

@Html.Sitecore().Placeholder("placeholdername") // this works

#7


0  

  <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="Kendo.Mvc.UI" />
    <add namespace="Telerik.Reporting" />
  </namespaces>

#8


-1  

I have added Sitecore.Mvc dll in references with copy local to true and added below tag in view's web.config under namespaces tag, then my problem is resolved.

我有添加Sitecore。Mvc dll在参考中带有复制本地到true,并在view的web中添加到标签下面。在名称空间标记下配置,那么我的问题就解决了。

#1


11  

I have the same problem a while ago. We found out that we are missing the web.config inside /views folder. we copy a web.config from my other projects' /views and it solved the issue.

我刚才也有同样的问题。我们发现我们错过了网络。内部配置文件夹/视图。我们复制一个网络。从我的其他项目/视图配置,它解决了问题。

#2


9  

Try This, then try to restart visual studio.

尝试此操作,然后尝试重新启动visual studio。

<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="Sitecore.Mvc" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

You forgot to add <add namespace="Sitecore.Mvc" /> so that intellisense can pick it up in VS.

您忘记添加 ,这样智能感知可以在VS中获取。

#3


4  

I have now resolved this issue. I simply had to install Update 2 of Visual Studio 2013. How frustrating.

我现在已经解决了这个问题。我只需要安装Visual Studio 2013的更新2。多么令人沮丧。

Thanks to StriplingWarrior and Ahmed Okour for your useful advice.

感谢StriplingWarrior和艾哈迈德·奥库尔提供的有益建议。

#4


2  

I have used the below line at the top and the issue has been resolved.

我已经在顶部使用了下面一行,问题已经解决。

@inherits System.Web.Mvc.WebViewPage

#5


1  

You say you're using MVC 5, but you're referencing version 3 in the code you provided. Here's what mine says:

您说您正在使用MVC 5,但是您在提供的代码中引用了version 3。这就是我说:

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Try checking through your entire web.config file (or all the web.config files if you have multiple Areas) and making sure that all the versions are set right. For MVC 5, System.Web.WebPages should be on version 2 and System.Web.WebPages.Razor should be on version 3.

试着检查你的整个网络。配置文件(或所有web文件)。配置文件(如果您有多个区域)并确保所有版本都设置正确。为MVC 5,包含。WebPages应该在版本2和System.Web.WebPages上。Razor应该在第三版。

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

...

  <assemblies>
    <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>

#6


0  

Sometimes its the silly things. Check you're not doing something like

有时是愚蠢的事情。检查你没有做类似的事情

@Html.Sitecore("placeholdername")   // no method

or

@Html.Sitcore.Placeholder("placeholdername") // Missing parenthesis

when you should be doing

当你应该做的时候。

@Html.Sitecore().Placeholder("placeholdername") // this works

#7


0  

  <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="Kendo.Mvc.UI" />
    <add namespace="Telerik.Reporting" />
  </namespaces>

#8


-1  

I have added Sitecore.Mvc dll in references with copy local to true and added below tag in view's web.config under namespaces tag, then my problem is resolved.

我有添加Sitecore。Mvc dll在参考中带有复制本地到true,并在view的web中添加到标签下面。在名称空间标记下配置,那么我的问题就解决了。