asp.net-mvc - Visual Studio 不在我的 Asp.net MVC View 中显示 Linq 扩展

标签 asp.net-mvc visual-studio-2010 configuration linq-extensions

这让我感到困惑,我似乎无法让 Visual Studio 2010 识别 View 代码中的 System.Linq 扩展方法。 Intellisense 不起作用,Visual Studio 红色下划线表示无法识别的扩展方法。

这些是 web.config 最相关的部分,我认为它们与 Visual Studio 相关以识别 System.Linq 扩展方法。注释掉的行可能未被注释,但没有区别。

<compilation debug="true" batch="true">
    <assemblies>
        <!--
        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        -->
        <add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </assemblies>
</compilation>

<pages enableViewState="false">
    <namespaces>
        <add namespace="System.Collections.Generic"/>
        <add namespace="System.Linq"/>
        <add namespace="System.Web.Mvc"/>
        <add namespace="System.Web.Mvc.Html"/>
        <add namespace="System.Web.Routing"/>
        <add namespace="MyApp.Objects"/>
        <add namespace="MyApp.Web.General"/>
        <add namespace="MyApp.Web.Helpers"/>
    </namespaces>
</pages>

我有一个看起来像这样的部分 View 定义。同样的关于注释掉两行。未注释没有区别:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IList<ToolbarItem>>" %>
<%--
<%@ Assembly Name="System.Core" %>
<%@ Import Namespace="System.Linq" %>
--%>
<%
    if (!this.Model.Any(ti => ti is ToolbarText && (ti as ToolbarText).MaximizeWidth))
    {
        this.Model.Add(new ToolbarText { MaximizeWidth = true });
    }
%>

在这个特定的部分 View 中,Any() 扩展方法无法识别,即使它是在 System.Linq 下的 System.Core 程序集中定义的命名空间。

我缺少哪些配置设置? Visual Studio 似乎看不到 System.Core 程序集来枚举它在 System.Linq命名空间。

最佳答案

您需要将 targetFramework 的属性添加到您的 web.config 中的编译元素:

<system.web>
    <compilation debug="true" targetFramework="4.0">

将其添加到您的 web.config 中,您应该会在您的 View 中重新获得智能感知。

关于asp.net-mvc - Visual Studio 不在我的 Asp.net MVC View 中显示 Linq 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4153504/

相关文章:

java - 在 Tomcat 应用程序中配置 logback

c# - MVC 4 表单例份验证 - 除了在 web.config 上声明的操作之外,无法访问任何其他操作

c# - ASP.NET MVC 条件验证

asp.net-mvc - 在 .NET 中使用 FB Connect/Google OAuth 登录

visual-studio-2010 - 如何在 Visual Studio 2010 中运行 SpecFlow 测试?

c++ - 第一次从现有的 main 编写头文件和 .cpp;无输出

c++ - 代码退出时出现奇怪的访问冲突

java - 使用 log4j2 将 System.out 写入文件

linux - 当您的 Debian Linux 服务器上已经有一个正在运行/工作/配置的 Nagios 实例时,是否可以部署 NConf?

asp.net-mvc - ASP MVC 中的自定义错误处理