具有RazorEngine的Linq命名空间

时间:2018-08-15 20:41:22

标签: c# linq razorengine

我正在尝试使用LINQ扩展方法在RazorEngine支持的剃刀视图中查询某些 strong 类型化的集合。问题是,它无法识别System.Linq命名空间。 @using System.Linq在Intellisense中产生错误:

  

类型或名称空间Linq在名称空间中不存在(您是   缺少程序集引用)

我正在寻找不安装WebPagesMVC软件包的解决方案。


我已经尝试过的东西(来自其他有关此处相关问题的答案):

  • 将RazorEngine.dll移动到bin
  • <add key="webpages:Version" value="3.0.0.0" />添加到a​​pp.config
  • <system.web><compilation debug="false" targetFramework="4.5.2" /></system.web>添加到a​​pp.config

每种方法都解决了一些问题:最初Intellisense根本不起作用,现在它可以识别以下System子命名空间:

  

CodeDom,集合,ComponentModel,配置,数据,
  部署,诊断,绘图,EnterpriseServices,全球化,   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>

1 个答案:

答案 0 :(得分:2)

只需将system.core.dll复制到项目的bin目录。

过去,我还发现有必要使用bin作为我的构建目录而不是bin\debug,但这似乎不再是必需的。

相关问题