从 ASP.NET MVC 4 更新到 MVC 5 的视图中没有智能感知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19500371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No Intellisense in views updating from ASP.NET MVC 4 to MVC 5
提问by user906573
I just updated an mvc4 project (using vs2012) to mvc5. After having a lot of issues related to dependencies, I finally found this tutorialand straightened things up so that it builds without issues However, I have to intellisense for any of the views (.cshtml files): @using, @model, @html.*, @styles... nothing works. I must have broken the reference to the razor view engine not being able to parse them properly. I have double checked the web.configs and cannot see anything. Any ideas? Thanks.
我刚刚将一个 mvc4 项目(使用 vs2012)更新为 mvc5。在遇到很多与依赖项相关的问题后,我终于找到了本教程并整理了一些内容,以便它可以毫无问题地构建但是,我必须对任何视图(.cshtml 文件)进行智能感知:@using、@model、@html .*, @styles... 没有任何效果。我一定打破了对无法正确解析它们的 razor 视图引擎的引用。我已经仔细检查了 web.configs 并且看不到任何东西。有任何想法吗?谢谢。
采纳答案by hatsrumandcode
ASP.NET and Web Tools 2013.1 for Visual Studio 2012 has now been released and should resolved the MVC5 intellisense issue with VS 2012.
Visual Studio 2012 的 ASP.NET 和 Web Tools 2013.1 现已发布,应该可以解决 VS 2012 的 MVC5 智能感知问题。
This release brings a ton of great improvements, and include some fantastic enhancements to ASP.NET MVC 5, Web API 2, Scaffolding and Entity Framework to users of Visual Studio 2012 and Visual Studio 2012 Express for Web.
此版本带来了大量重大改进,包括对 Visual Studio 2012 和 Visual Studio 2012 Express for Web 用户的 ASP.NET MVC 5、Web API 2、脚手架和实体框架的一些出色增强。
You can download the update: http://blogs.msdn.com/b/webdev/archive/2013/11/18/announcing-release-of-asp-net-and-web-tools-2013-1-for-visual-studio-2012.aspx
您可以下载更新:http: //blogs.msdn.com/b/webdev/archive/2013/11/18/annoucing-release-of-asp-net-and-web-tools-2013-1-for-视觉工作室-2012.aspx
回答by Dennis Puzak
Went through the same agony, and was working without intellisense in views for about 3 weeks. Then I finally found it. It started working when I switched webpages setting to version 3 in web.config.
经历了同样的痛苦,并且在没有智能感知的情况下工作了大约 3 周。然后我终于找到了。当我在 web.config 中将网页设置切换到版本 3 时,它开始工作。
So in my web.config this was version 2.0.0.0, after i updated to 3.0.0.0 it started to work
所以在我的 web.config 这是版本 2.0.0.0,在我更新到 3.0.0.0 之后它开始工作
<appSettings>
<add key="webpages:Version" value="3.0.0.0"/>
...
</appSettings>
Hopfully this was your issue to and will help becouse I feel your pain :)
幸好这是你的问题,因为我感受到你的痛苦,这会有所帮助:)
--------------------------------------------------------
-------------------------------------------------- ------
UPDATE:For others who are still looking for a fix for this issues in a post-MVC5 update, this helped me: In the ~/Views/web.config, updating from MVC 5.2.2.0 to 5.2.3.0 using Nuget did not update this line:
更新:对于仍在 MVC5 之后的更新中寻找此问题修复程序的其他人,这对我有帮助:在~/Views/web.configMVC 5.2.2.0 到 5.2.3.0 中使用 Nuget 更新没有更新此行:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Updating 5.2.2.0to 5.2.3.0brought Intellisense back to life. You may have to close the view and re-open it to get the Intellisense to load.
更新5.2.2.0到5.2.3.0带智能感知起死回生。您可能需要关闭视图并重新打开它才能加载 Intellisense。
回答by Diego_DX
I had try all that and other stuffs in my case the solution was changes this line that is in Views-WebConfig inside
在我的情况下,我尝试了所有这些和其他东西,解决方案是更改 Views-WebConfig 中的这一行
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
to
到
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
回答by Francisco Goldenstein
None of the previous solutions worked for me. I'm using VS 2012 and MVC 5. This is what I did to make it work:
以前的解决方案都不适合我。我正在使用 VS 2012 和 MVC 5。这是我为使其工作所做的工作:
- I installed Web Tools 2013 as explained in the following link: http://blogs.msdn.com/b/webdev/archive/2013/11/18/announcing-release-of-asp-net-and-web-tools-2013-1-for-visual-studio-2012.aspx
I checked /web.config and /Views/web.config and fixed some version issues. In my case I have MVC 5.2 so it was important to do a correct MVC biding like this:
- 我按照以下链接中的说明安装了 Web Tools 2013:http: //blogs.msdn.com/b/webdev/archive/2013/11/18/annoucing-release-of-asp-net-and-web-tools- 2013-1-for-visual-studio-2012.aspx
我检查了 /web.config 和 /Views/web.config 并修复了一些版本问题。在我的例子中,我有 MVC 5.2,所以像这样做一个正确的 MVC 投标很重要:
Also, it's important to mark this:
此外,重要的是要标记这一点:
<add key="webpages:Version" value="3.0.0.0" />
回答by PTK
While the above answers may resolve most of these problems, my problem was apparently caused by a VS Extension I had installed. Please see Answer provided by Emran Hussain here: Visual Studio 2013 IntelliSense stops working for ASP.NET MVC5 Controllers
虽然上述答案可能会解决大部分问题,但我的问题显然是由我安装的 VS 扩展引起的。请在此处查看 EmranHussain 提供的答案:Visual Studio 2013 IntelliSense 停止为 ASP.NET MVC5 控制器工作
His answer was spot on for me, even though my problem was with intellisense on my Razor Views only. I disabled the extension, and restarted VS2013 and intellisense is working again with no problems. Like Emran, I'm hesitant to blame the maker of the extension (AzureXplorer by ClumsyLeaf software), because I think this may be a VS issue?
他的回答对我来说是正确的,即使我的问题仅在于我的 Razor Views 上的智能感知。我禁用了扩展,并重新启动了 VS2013,智能感知再次正常工作,没有任何问题。和 Emran 一样,我也不愿责怪扩展程序的制造商(ClumsyLeaf 软件的 AzureXplorer),因为我认为这可能是 VS 问题?
回答by o_o
The tooltip of the "@model" tag at the very top of my razor view file stated that autofac 3.4.0.0 could not be found. All my projects used Autofac 3.1.5, so I added a redirect in web.config to quickly work around the issue:
我的剃刀视图文件最顶部的“@model”标签的工具提示指出无法找到 autofac 3.4.0.0。我所有的项目都使用 Autofac 3.1.5,所以我在 web.config 中添加了一个重定向来快速解决这个问题:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.4.0.0" newVersion="3.1.5" />
</dependentAssembly>
...
My intellisense was back and I then deferred the final fix to a low prio task :D
我的智能感知回来了,然后我将最终修复推迟到低优先级任务:D

