我的cshtml中没有intellisense。我的web.config (视图文件夹)中有:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.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" />
<add namespace="System.Web.Optimization"/>
<add namespace="EO2.Models" />
<add namespace="EO2" />
<add namespace="EO2.Resources"/>
</namespaces>
</pages>
</system.web.webPages.razor>
只有在我的cshtml中添加@using MyNamespace
时,它才能工作。
我检查了这里列出的所有版本编号:MVC Razor view Intellisense broken in VS 2013/2015/2017 Intellisense in razor files (.cshtml) not work
编辑:问题出现在VS或其他项目文件中?我在每个新的解决方案中都有同样的问题。
发布于 2015-09-18 13:57:37
工具->导入/导出设置->重置设置
为我做的
发布于 2019-06-14 23:08:49
尝试切换构建配置并删除obj
我已经好多年没遇到这个问题了,突然就开始了。
>------ Build started: Project: MyMVC, Configuration: Debug Any CPU ------
6>S:\TFS\RRStore\RRStore.Main\MyMVC\obj\CodeGen\obj\Release\Package\PackageTmp\Areas\Store\Views\Products\Category\SearchPanel\Search.cshtml.cs(22,26,22,27): error CS0116: A namespace cannot directly contain members such as fields or methods
========== Build: 5 succeeded, 1 failed, 9 up-to-date, 0 skipped ==========
等一下!我正在做一个调试构建,它在抱怨obj\Release
因此,我完全删除了obj
并得到了以下错误:
15>------ Rebuild All started: Project: MicroPedi_MVC, Configuration: Debug Any CPU ------
15>...RazorGenerator.MsBuild.targets(44,9): error : Could not find a part of the path 'S:\TFS\RRStore\RRStore.Main\My_MVC\obj\Release\Package\PackageTmp\Areas\Admin\Views\CallCenter\Index.cshtml'.
========== Rebuild All: 14 succeeded, 1 failed, 0 skipped ==========
!那个文件夹根本不存在(obj\Release
)!
所以我切换到了Release
配置。一切都建好了。现在,如果我回想起来,这并不能证明什么,因为我认为我使用的是预编译的视图- tbh,我忘记了它是如何工作的。
无论如何,我切换回了Debug
配置。
一切都突然起作用了!
如果这没有帮助的话,那就试试一些基本的侦探工作吧,假设什么都不起作用!
我发现它在我的服务器上构建得很好,我很长时间没有对我的web.config做任何更改。
\obj\CodeGen\obj\Release\Package\PackageTmp\Areas\Store\Views\Products\Products.cshtml.cs
\obj\CodeGen\...
或obj
中的所有内容另一种可能性是:
我最近安装了.NET Framework1.1(以便能够提取我需要的第三方库)。
不管怎么说,我还是卸载了它,但不清楚这是否是任何事情出错的原因。不过,很可疑--尤其是从1.1开始。总是喜欢捣乱IIS。
发布于 2021-05-19 13:44:20
我建议:
这将修复错误并使生成再次成为可能。
https://stackoverflow.com/questions/32652608
复制相似问题