c# - Visual Studio 智能感知搞砸了

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

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

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

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

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

Example Images :

enter image description here enter image description here enter image description here enter image description here 您几乎无法阅读的长错误指出

System.Web.WebPages.Html.htmlHelper' does not contain a definition for 'Actionlink' .... missing assembly reference ?

对于 Razor View 中的任何 @codes 以及 C# @'s,我都会收到此错误

WebConfig File

<?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>

最佳答案

确保您在 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>

还要确保您的 View 位于它们的标准位置(也就是 ~/Views 文件夹)。

关于c# - Visual Studio 智能感知搞砸了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17598359/

相关文章:

c# - 如何将数据发布到数据库并将其绑定(bind)到同一 View 中的网络网格?

c# - 'CompanyName.Foo' 是一个 'namespace' 但像 'type' 一样使用

c# - 从 C# 中的类型以编程方式生成 XSD - 在子类 XSD 中包含基类属性

c# - 使用独立模块管理器加载 Prism 模块

c# - 如何绑定(bind)自定义类型的集合 (IEnumerable)?

c# - 如果身份角色不是管理员,则从 Web Api 重定向到 MVC Controller

c# - 在执行当前 Web 请求期间生成了未处理的异常。[HttpAntiForgeryException]

c# - 当没有剩余内存时,.Net 和 Bitmap 不会被 GC 自动处理

c# - 从 1 个项目列表创建 2 列项目列表

asp.net-mvc - 使用 Html.ActionLink 传递文本框值