Using a Razor For loop on an IEnumerable ViewModel - problems accessing by index
<p>I am aware that you can't access a value by index when using an <code>IEnumerable&lt;T&gt;</code> .</p>

<p>Here is my view:</p>

<pre><code>@model IList&lt;CustomerViewModel&gt;

@for (int i = 0; i &lt; Model.Count - 1; i++)
{
     @Model[i].Name
}
</code></pre>

<p>Notice how I need to make the <code>ViewModel</code> of type <code>IList</code> in order to use index.</p>

<p>Here is my controller:</p>

<pre><code>public IActionResult Index()
{
    IList&lt;Customer&gt; customers = _ctx.Reviews.GetCustomers().ToList();

    return View(customers.Select(c =&gt; Mapper.Map&lt;CustomerViewModel&gt;(c)));
}
</code></pre>

<p>I am getting an error that is saying that the model item passed into the <code>ViewDataDictionary</code> is incorrect.</p>

<p>This makes sense because I guess an IQueryable is going in? Which is why I am trying to keep the <code>ViewModel</code> of type <code>IEnumerable</code> and still use a for loop.</p>