Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
<p>I have the following code inside my view inside an asp.net mvc-4 web application:-</p>

<pre><code>@model IList&lt;TS.ViewModels.ACCOUNTLIST&gt;

@for(int i2 = 0; i2 &lt; (Model.Count() &lt;= 0 ? 5 : Model.Count()); i2++) { 

    &lt;div&gt;

        &lt;span &gt;@Html.DisplayFor(m =&gt; m[i2].ACCOUNTNAME) &lt;/span&gt;@Html.EditorFor(m =&gt; m[i2].ACCOUNTNAME) &lt;/div&gt;
          &lt;div&gt;

        &lt;span &gt;@Html.DisplayFor(m =&gt; m[i2].PASSWORD) &lt;/span&gt;@Html.EditorFor(m =&gt; m[i2].PASSWORD) &lt;/div&gt;
          &lt;div&gt;

        &lt;span &gt;@Html.DisplayFor(m =&gt; m[i2].NOTES) &lt;/span&gt;@Html.EditorFor(m =&gt; m[i2].NOTES) &lt;/div&gt;

} 
</code></pre>

<p>now what i am trying to accomplish is to display a five empty set of fields if the Model is empty. and in-case the Model contain data to display the related date.. but currently when i render the view and the passed model is empty i will get the following exception :-</p>

<pre><code>Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index 
</code></pre>

<p>but if i use <code>Html.Display</code> and <code>Html.Editor</code> as follow , my view will work well:-</p>

<pre><code>@for(int i2 = 0; i2 &lt; (Model.Count() &lt;= 0 ? 5 : Model.Count()); i2++) { 

    &lt;div&gt;

        &lt;span class="f"&gt;@Html.Display("["+i2.ToString()+"].ACCOUNTNAME") &lt;/span&gt;@Html.Editor("["+i2.ToString()+"].ACCOUNTNAME") 


        &lt;span class="f"&gt;@Html.Display("["+i2.ToString()+"].PASSWORD") &lt;/span&gt;@Html.Editor("["+i2.ToString()+"].PASSWORD") &lt;/div&gt;




} 
</code></pre>

<p>So can anyone adivce on this please? why i can not use the <code>Html.DisplayFor</code> &amp; <code>Html.EditorFor</code> in my case?</p>