简体   繁体   English

Views Web.config中的名称空间上没有智能感知

[英]No intellisense on namespaces in Views Web.config

I have a MVC5 project I am trying to solve some issues with where I am not getting intellisense on the System.Web.MVC components 我有一个MVC5项目,我正在尝试解决一些有关System.Web.MVC组件上没有智能感知的问题。

In the Web.Config in my views folder I have the following; 在我的views文件夹中的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.Configuration" />
        <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="Helpers" />
        <add namespace="Common.Net.Mvc" />
        <add namespace="Common" />
        <add namespace="MvcSiteMapProvider.Web.Html" />
        <add namespace="MvcSiteMapProvider.Web.Html.Models" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

However when I then reference for example Url., ViewBag or Html.ActionLink etc(also if I reference my Common class which is a .resx generated file). 但是,当我然后引用例如Url。,ViewBag或Html.ActionLink等时(同样,如果我引用的是我的Common类,它是.resx生成的文件)。 I get errors saying they do not existing the current context. 我收到错误消息,说它们不存在当前上下文。

I can compile and run the code successfully and the pages render just fine, it would be nice to eliminate these errors though and get the intellisense I usually get. 我可以成功地编译并运行代码,并且页面呈现得很好,尽管可以消除这些错误并获得我通常得到的智能感知将是很好的。

I am running VS2017 Community and I have the Razor extension installed and updated. 我正在运行VS2017社区,并且已安装和更新Razor扩展。 I have intellisense on other projects it just seems to be this one. 我在其他项目上有智慧,似乎就是这个项目。

Ok, After much searching and wasting of time, this answer here fixed the issue; 好吧,经过大量的搜索和浪费的时间,这里的答案解决了这个问题;

The name 'ViewBag' does not exist in the current context - Visual Studio 2015 当前上下文中不存在名称“ ViewBag”-Visual Studio 2015

Here is a run down of the steps I took (the removal and deletion of files may not be required); 这是我执行的步骤的摘要(可能不需要删除和删除文件);

  1. Delete the .suo and .csproj.user from the solution having the issues. 从存在问题的解决方案中删除.suo和.csproj.user。
  2. Delete the hidden .vs folder form the route of the solution 从解决方案的路径中删除隐藏的.vs文件夹
  3. Delete the temp asp net files from 从中删除temp asp net文件

C:\\Users\\your.name.here\\AppData\\Local\\Temp\\Temporary ASP.NET Files C:\\ Users \\您的名称。此处\\ AppData \\ Local \\ Temp \\ Temporary ASP.NET文件

  1. Delete the files fro here; 从此处删除文件;

C:\\Users\\your.name.here\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\ComponentModelCache C:\\ Users \\您的名称。此处\\ AppData \\ Local \\ Microsoft \\ VisualStudio \\ 14.0 \\ ComponentModelCache

Note the above alone didn't fix so then I applied the following in conjunction witht he above. 请注意,仅靠上面的方法并不能解决问题,因此我在上面结合了以下内容。

  1. Compared the .csproj version info with that of the project with the issue and ammend (as it was indeed a project carried over form VS 2012) and as per the link above. 将.csproj版本信息与该项目的.csproj版本信息进行了比较,并添加了问题和修正(因为这确实是从VS 2012继承过来的项目),并且按照上面的链接进行了比较。

csproj图片

  1. Right click the solution -> 'Manage Nuget Packages...' -> Updates -> select all -> apply updates 右键单击解决方案->'Manage Nuget Packages ...'->更新->全选->应用更新

This rebuilt the nuget references and the intellisense came back. 这重建了nuget参考,并且智能感知又回来了。 Hopefully one day, somewhere this will help. 希望有一天,这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM