2012-06-06 25 views
13

我在Visual Studio 10中創建了一個MVC3應用程序。編輯視圖時,「@Model」,「@Viewbag」和「@Url」全部顯示有效。「@Model」,「@Viewbag」和「@Url」「在當前上下文中不存在」使用Visual Studio 11 Beta/Visual Studio 2012 RC時Razor MVC3

我最近安裝了Visual Studio 11 Beta,並且在編輯(或創建)視圖時,我在上面的關鍵字中得到「x在當前上下文中不存在」錯誤,顯然沒有任何智能感。

我已經安裝了Visual Studio 2012 RC,希望它只是一個Visual Studio 11 Beta問題....它不是。由於在Visual Studio 2012 RC中運行它,我注意到了「@Html」關鍵字,但是智能檢測列表是有限的 - 與模型相關的任何內容(例如「@ Html.EditorFor()」)和任何在「渲染」系列中失蹤。

如果我運行該項目一切都很好。

現在,如果我在Visual Studio 11 Beta/2012 RC中創建了一個新項目,則所有關鍵字都被識別。

在我的項目文件中是否需要編輯以使其正常工作?

編輯 - 更多的答案,從我的評論下面複製 對於人們升級到VS 2015年,它不支持MVC 4,你需要升級項目MVC5。見 - http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

+0

我一起工作的一個傢伙昨天基本上這個確切的錯誤VS11。智能感知不會看到任何「@ Html.」,但代碼運行良好。不幸的是,我現在找不到他的SO帖子來交叉鏈接它們......但是我聞到了一個VS bug ... – CodingWithSpike

+0

對於升級到VS 2015的人來說,它不支持MVC 4你需要升級項目到MVC5 - http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and -web-api-2 –

回答

16

將以下設置添加到您的主web.config文件的appSettings部分:

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

通過Connect:http://connect.microsoft.com/VisualStudio/feedback/details/732597/visual-studio-11-beta-razor-intellisense-not-working

+0

就是這樣!謝謝!我猜我的Google搜索有點過於具體。 –

+0

謝謝,這讓我瘋狂! – conroyrw

+8

隨着Visual Studio的發佈版本(剛剛發佈),我必須刪除網頁1.0.0.0條目,並返回使用以便獲得智能感知。 – gdoten

5

爲vs2015的更新;

在你的主要的web.config

<dependentAssembly> 
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
    </dependentAssembly> 

,並放在您的網頁的 「NEWVERSION」 參數查找這個元素:版本

<add key="webpages:Version" value="3.0.0.0" /> 
+0

你有沒有修復VS 2013? –

相關問題