【发布时间】:2018-08-15 20:41:22
【问题描述】:
我正在尝试使用 LINQ 扩展方法在 RazorEngine 支持的剃刀视图中查询一些 strong>强 类型的集合。问题是,它无法识别System.Linq 命名空间; @using System.Linq 在 Intellisense 中生成错误:
命名空间中不存在类型或命名空间 Linq(你是 缺少程序集参考)
我正在寻找不安装 WebPages 或 MVC 软件包的解决方案。
我已经尝试过的事情(来自此处相关问题的其他答案):
- 将 RazorEngine.dll 移动到 bin
- 将
<add key="webpages:Version" value="3.0.0.0" />添加到app.config - 将
<system.web><compilation debug="false" targetFramework="4.5.2" /></system.web>添加到app.config
这些措施中的每一个都解决了一些问题:最初 Intellisense 根本不起作用,现在它可以识别以下 System 子命名空间:
CodeDom、集合、组件模型、配置、数据、
部署、诊断、绘图、企业服务、全球化、 IO、媒体、网络、反射、资源管理器、运行时、安全性、文本、
线程、定时器、Web、Windows、Xml
我的观点片段:
@using RazorEngine.Template
@using System.Linq <!--namespace doesn't exist in System-->
@using Namespace.Of.My.Models
@inherits TemplateBase<ThisPageModel>
<table class="my-table-class">
<thead>
<tr>
<th>Column1</th>
</tr>
<tr>
<th>Column2</th>
</tr>
</thead>
<tbody>
@foreach(var item in Model.Children)
{
<tr>
<td>
@item.ListOfThings.First() <!--List<Things> does not contains a definition for First-->
</td>
</tr>
}
</tbody>
</table>
【问题讨论】:
-
请从您的角度发布代码。我有使用 Linq 没有问题的强类型视图,因此需要查看您的代码才能知道它为什么不起作用。
-
@codeMonkey 添加了一个 sn-p!
-
谢谢!好吧,我正在使用 MVC,所以也许这就是区别。你签出this link了吗?
-
确保项目的构建目录只是bin/(不是默认的bin/debug/)并将system.core.dll复制到bin目录。
-
@codeMonkey 谢谢!我假设使用 MVC 包含 VS 识别命令所需的包?显然,将 MVC 添加到项目中解决了这个问题,但我正在寻找一种方法来解决这个问题,而不会使解决方案变得臃肿。
标签: c# linq razorengine