Asp.net-Mvc

在VS2012中打開一個MVC3項目

  • October 2, 2012

我正在嘗試在新安裝的 Visual Studio Express 2012 RC 中打開 MVC3 解決方案。到目前為止,我遇到了一些問題,由於某種原因 VS2012 不知道這些項目是 MVC 項目,所以它不會添加視圖/控制器。通過將以下 GUID 添加到解決方案中每個項目ProjectTypeGuids的文件節點來解決此問題:.csproj

{E53F8FEA-EAE0-44A6-8774-FFD645390401}

但是,當我打開剃刀視圖時,它會顯示以下錯誤(以及其他相關錯誤):

Error    20    The name 'model' does not exist in the current context    c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml    2    2    EventManagement

Error    21    The name 'T' does not exist in the current context    c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml    5    14    EventManagement

Error    22    'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'LabelFor' and no extension method 'LabelFor' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)    c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml    6    11    EventManagement

Intellisense 正在剃刀視圖中工作,但它只為 Html 輔助方法提供有限數量的欄位。例如,沒有任何特定於模型的方法,如 LabelFor 和 TextboxFor。

我安裝了 MVC 3 和 4。該解決方案在 VS2010 中執行良好。

更新:

在 VS2012 中添加的MVC3 項目時,它工作正常。所以這意味著它肯定與項目有關,而不是與安裝有關。

更新2: 我認為問題在於視圖無權訪問根配置中的引用庫:

<system.web.webPages.razor>
 <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.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="System.Web.WebPages" />
     <add namespace="System.Linq"/>
     <add namespace="System.Collections.Generic"/>
     <add namespace="Orchard.Mvc.Html"/>
   </namespaces>
 </pages>
</system.web.webPages.razor>

它在執行時執行,但智能感知和錯誤控制台不接受它

任何幫助表示讚賞。

謝謝

對我來說,這個問題是通過添加解決的:

<add key="webpages:Version" value="1.0.0.0"/>

在我的根 web.config 的 appSettings 部分

例如

<appSettings>
    <add key="webpages:Version" value="1.0.0.0"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
 </appSettings>

檢查此連結:

http://msdn.microsoft.com/en-us/library/hh266747(v=vs.110).aspx

確保您知道該項目是 MVC3。確保該項目是使用帶有 SP1 的 VS2010 創建的。

引用自:https://stackoverflow.com/questions/11435790