在ASP.NET MVC视图中将IEnumerable转换为数组或列表

3
在Views中似乎只有少量的库(是真的吗?)可用,如下所示:a screenshot showing the available methods for the IEnumerable 我的问题是,如何将IEnumerable转换为数组或列表?在普通的C#文件中,我通常可以使用像ToArray()、ToList()或Cast<T>()这样的方法,但当涉及到Views(在ASP.NET MVC中)时,它们似乎都消失了。
1个回答

11

<%@ import namespace='System.Linq' %>

您还可以在Web.config中添加您的命名空间,例如:

<system.web>
  <pages>
    <namespaces>
      <add namespace='System.Linq' />
    </namespaces>
  </pages>
</system.web>

你可能想要双引号? - William Niu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接