7
Answers

foreach loop doesn't know [i]

Cassie Mod

Cassie Mod

8y
308
1
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)