11

我有一個似乎已經在這裏報告了一個問題:剃刀編譯器警告/錯誤 - ASP.NET MVC 4

Need razor view engine auto-complete to work in a class library?

我的問題是以下警告:

G:\Accountable\Accountable\Views\LedgerUser\EditorTemplates\LedgerServiceViewModel.cshtml: ASP.NET runtime error: There is no build provider registered for the extension '.cshtml'. You can register one in the section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.

這我的觀點顯而易見。下面的示例圖像。

enter image description here

enter image description here

enter image description here

現在的所有帖子,並在網上,我發現引用引用來添加各種Web.config文件(如前面的文章中提到)的選擇,但是這並未似乎沒有用,因爲我在這個項目中默認了這些配置。這裏是我的Web CONFIGS:

Main Web.config

View root Web Config

我想這個問題也許同時IM也越來越上查看以下編譯器錯誤:

The name 'Html' does not exist in the current context

enter image description here

什麼我做錯了嗎?

+0

這一個幾乎重複:http:// stackoverflow。com/questions/4158573/need-razor-view-engine-auto-complete-to-work-in-a-class-libraries –

+0

嘿大衛。感謝您的評論。是的,我在上面的帖子中提到過。我看不出在項目中創建的默認區別。 – garfbradaz

回答

21

Arrrgghhh我已經錯過了從根web.config以下:

<compilation debug="true" targetFramework="4.0"> 
    <!-- New --> 
    <assemblies> 
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </assemblies> 
</compilation> 

這使得固定的錯誤,讓我在視圖中使用智能感知。

+1

我不知道爲什麼這個固定它,但它確實。它運行良好,然後我在git中的文件上扭轉了一個非常小的塊,並且我的整個項目都爆炸了。這似乎解決了它。 –

+1

這適用於mvc5,只需將版本更改爲'3.0.0.0',並將公用密鑰更改爲web.config文件中的公鑰(它位於文件末尾)。 MVC 5中的 – VSG24

+0

更新了所有版本和密鑰,但錯誤仍在此處。 –

3

放回在根Web.config以下行固定:

<system.web> 
    <pages> 
     <namespaces> 
     <add namespace="System.Web.Helpers" /> 
     <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="System.Web.WebPages" /> 
     </namespaces> 
    </pages> 
</system.web> 
2

我把它簡單地卸載和重裝該項目的工作。上面的所有命名空間已經存在於根web.config中,我仍然遇到這個問題。

2

刪除臨時asp.net框架文件適用於我。

停止IIS,並刪除所有該文件夾下:

C:\Windows\Microsoft.NET\Framework64\[framework version]\Temporary ASP.NET Files

然後重新啓動IIS。巴姆!

+1

由於沒有明顯原因開始接收此錯誤 - 我的項目多年前一直在運行。這對我有用,謝謝! – Jesse

0

我嘗試通過重新啓動IIS,刪除臨時ASP.NET文件並更改web配置文件中的編譯標籤。他們都沒有爲我工作。

我通過刪除和添加System.Web.MVC到項目中解決了問題。

在我的情況下,Razor語法突出顯示爲紅色。