Visual Studio 不在我的 Asp.net MVC 视图中显示 Linq 扩展
这让我感到困惑,我似乎无法使 Visual Studio 2010 识别视图代码中的 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>
我有一个看起来像这样的部分视图定义。同样注释掉了两行。未注释没有区别:
<%@ 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 });
}
%>
在这个特定的部分视图中,Any()
扩展方法无法识别,即使它是在 System.LinqSystem.Core
程序集中定义的。代码 > 命名空间。
我缺少哪些配置设置? Visual Studio 似乎无法看到 System.Core
程序集来枚举它在 System.Linq
命名空间中的扩展方法。
This baffles me and I can't seem to make Visual Studio 2010 to recognise System.Linq extension methods in view code. Intellisense doesn't work and Visual Studio red underlines unrecognised extension methods.
These are web.config's most relevant parts, that I think are related to Visual Studio to recognize System.Linq extension methods. Commented out lines may be uncommented but there's no difference.
<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>
I have a partial view definition that looks like this. The same about commented out two lines. Uncommented make no difference:
<%@ 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 });
}
%>
In this particular partial view Any()
extension method is not recognised even though it's defined in System.Core
assembly under System.Linq
namespace.
Which config settings am I missing? Seems that Visual Studio can't see System.Core
assembly to enumerate it's extension methods in System.Linq
namespace.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以尝试
where * 是您想要使用的命名空间,例如 System.Linq
可能不是最好的方法,但它可能有效(不适用于带有 vs 的计算机,因此无法测试)
could try
where * is the namespace you want to use e.g. System.Linq
probably not the best way to do but it may work (not at a computer with vs so cant test)
当然,
System.Core
程序集必须包含在配置编译中。但是,当我清理
web.config
文件时,我删除了这部分,这对于 Visual Studio 2010 来说是必要的(显然),以使事情按预期工作。Of course
System.Core
assembly has to be included in the configuration compilation.But when I was cleaning up my
web.config
file I deleted this part, that is imperative (obviously) to Visual Studio 2010 to make things work as expected.您需要将 targetFramework 的属性添加到 web.config 中的编译元素中:
将其添加到 web.config 中,您应该在视图中再次重新获得智能感知。
You need to add the attribute of targetFramework to the compilation element in your web.config:
Add that to your web.config and you should regain intellisense again in your views.