0
votes

I have in my view :

@if (Model.Count() > 0)
{
    @foreach (var item in Model)
    {

         <tr rowid="@item.SupplyPoints.First().SupplyPointId" >
         ...
     }

But I get a "Sequence contains no elements" error message. How is that possible, as if my list was empty i don't go in the @if ? I've also checked in the controller, my list have elements... What can i do? Thx

1
Model.Count() and item.SupplyPoints seem unrelated. - Henk Holterman

1 Answers

0
votes

The exception is coming from First(). One of your items don't have anything in its SupplyPoints collection.

First() will throw an exception when the collection is empty.

Enumerable.First Method