Cassie Mod

Cassie Mod

  • NA
  • 488
  • 70.5k

foreach loop doesn't know [i]

Feb 4 2016 3:57 AM
HI,
 
Ive got the following easy question.
 
I had a for loop, however when i set it in a foreach loop it doesn;t know "[I] . How can i fix this???
 
for lop:
 
  @for (int i = 0; i < 2; i++)
{
<div class="col-lg-2 col-xs-2 col-sm-2 col-md-2">
@Html.Partial("_CollectorStatusOne", Model.CollectorStatus.FirstOrDefault(cs => cs.CollectorID == Model.Collectors.ToList()[i].CollectorID))
</div>
}
 
foreach loop:
@foreach (var item in Model.Collectors)
{
<div class="col-lg-2 col-xs-2 col-sm-2 col-md-2">
@Html.Partial("_CollectorStatusOne", Model.CollectorStatus.FirstOrDefault(cs => cs.CollectorID == Model.Collectors.ToList()[i].CollectorID))
</div>
}

Answers (7)