【问题标题】:Visual studio intellisense messing up视觉工作室智能感知搞砸了
【发布时间】:2013-07-10 00:27:19
【问题描述】:

所以我是 MVC4 和 C# 的新手,我已经设计这个网站大约 2 周了,智能感知没有任何问题。

Visual Studio 2 天以来一直告诉我 @Viewbag 和其他 @ 命令不是我的项目的一部分,我可能遗漏了一些东西,或者它告诉我 Viewbag 在当前上下文中不存在。

我不确定如何解决这个问题(我已经重新启动了项目并且正在使用的机器)仍然显示有下划线并告诉我它在上下文中不存在

因为当我查看/尝试新代码时我还是新手,所以这非常困难,因为 一切 都是错误的..

示例图片:

您几乎无法阅读的长错误表明

System.Web.WebPages.Html.htmlHelper' 不包含 'Actionlink' 的定义 .... 缺少程序集参考?

对于 Razor 视图中的任何 @code 以及 C# @'s 除外,我都会收到此错误

网络配置文件

<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
 -->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit   http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=ANE-SQL\ANESQLSERVER;Database=OilGas;User Id=software;Password=GLvp$102;" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
 <add key="webpages:Version" value="2.0.0.0" />
 <add key="webpages:Enabled" value="false" />
 <add key="PreserveLoginUrl" value="true" />
 <add key="ClientValidationEnabled" value="true" />
 <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>

<customErrors mode="RemoteOnly"></customErrors>


<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="180" />
</authentication>
<pages>
  <namespaces>
    <add namespace="System.Web.Helpers" />
    <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="System.Web.WebPages" />
  </namespaces>
</pages>



</system.web>
<system.webServer>
<!--<modules runAllManagedModulesForAllRequests="true" />-->
<validation validateIntegratedModeConfiguration="false" />
<handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*."   verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
   <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"   preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*."   verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"    type="System.Web.Handlers.TransferRequestHandler"    preCondition="integratedMode,runtimeVersionv4.0" />
  </handlers>
  </system.webServer>
  <runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
    </dependentAssembly>
    </assemblyBinding>
   </runtime>
    <entityFramework>
    <defaultConnectionFactory    type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="v11.0" />
     </parameters>
    </defaultConnectionFactory>
  </entityFramework>
    </configuration>

【问题讨论】:

  • 你还能编译和运行你的项目吗?
  • 您使用的是什么版本的 Visual Studio 和 Windows?
  • VS 2012 Prem , 7 专业

标签: c# asp.net-mvc asp.net-mvc-4 razor intellisense


【解决方案1】:

确保您已在 web.config 的 appSettings 中指定您正在使用的 Razor 版本:

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

还要确保您的视图位于其标准位置(也称为~/Views 文件夹)。

【讨论】:

  • 改成你上面显示的代码,没用,甚至试过设置 ---- 没有效果,全部我的视图在 ../Views 中,让我发布我的 web.config 文件,看看你能不能找到不属于的东西?
  • 在我的情况下,将&lt;add key="webpages:Version" value="2.0.0.0" /&gt; 更改为&lt;add key="webpages:Version" value="3.0.0.0" /&gt; 可以解决问题。在我的机器上安装了 VS 2015 并且在新的 Web 项目上,剃须刀智能工作,但在旧机器上 - 没有。不同之处在于 web.config 网页:版本。
【解决方案2】:

创建一个新的 Internet Web 应用程序取出您的更改(从旧代码中)插入新创建的 Internet Web 应用程序配置文件,添加旧更改(逐行跳过所有阅读内容,看看是否真的搞砸了)

希望有帮助

【讨论】:

  • 我刚刚发现 appSettings 需要在 Web.config 文件中设置得很高,否则它会让 Intellisense 发疯。我把我的放在 元素下方(因为 IIS 要求它首先出现)。
【解决方案3】:

在我错误地将&lt;appSettings&gt; 添加到 Views Web.config 而不是“主”Web.config 文件后,遇到了同样的问题。我花了几个小时才弄明白...

希望它对某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-17
    • 2016-10-20
    • 2018-12-02
    • 2011-10-10
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    相关资源
    最近更新 更多