William Niu
William Niu

Reputation: 15853

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: a screenshot showing the available methods for the IEnumerable

My question is how do I convert an IEnumerable to, say, an array or a list? 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).

Upvotes: 3

Views: 2444

Answers (1)

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56182

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

You can also add your namespace in the Web.config, i.e.:

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

Upvotes: 11

Related Questions