[英]Convert IEnumerable (to array, list) in ASP.NET MVC View
It seems that in Views, there is limited libraries available (is it true?), see below:似乎在 Views 中,可用的库有限(是真的吗?),见下文:
My question is how do I convert an IEnumerable to, say, an array or a list?我的问题是如何将 IEnumerable 转换为数组或列表? I normally can use methods like
ToArray()
, ToList()
, or Cast<T>()
in a regular C# file, but they all seem to have disappeared when it comes to Views (in ASP.NET MVC).我通常可以在常规 C# 文件中使用诸如
ToArray()
、 ToList()
或Cast<T>()
之类的方法,但是在涉及视图时它们似乎都消失了(在 ASP.NET MVC 中)。
<%@ import namespace='System.Linq' %>
You can also add your namespace in the Web.config
, ie:您还可以在
Web.config
中添加您的命名空间,即:
<system.web>
<pages>
<namespaces>
<add namespace='System.Linq' />
</namespaces>
</pages>
</system.web>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.