Collection does not allow foreach

Asked

Viewed 179 times

-2

I have a collection and inside I have another collection of images. I need to do a chained foreach to get information from the first collection, and then the second foreach to get the images I have referring to the first looping.

Here is my code:

@foreach ( var item in Model )
{
    <div class="title-pagina-interna">
        <h2>@item.Titulo</h2>
    </div>

    <div class="container-carrossel">
        @foreach (Imagem teste in item.Thumb)

But the following error is returning to me:

foreach statement cannot Operate on variables of type 'Webprovider.Mbw_incentivo.domain.Models.Imagem' because 'Webprovider.Mbw_incentivo.domain.Models.Imagem' does not contain a public Definition for 'Getenumerator'

How can I fix this?

  • 1

    A good start would be formatting the question better, and pasting the code into the text. Read here how to format your code: http://answall.com/editing-help

1 answer

2

The type of property Thumb of your item is not an image collection; it is an image only, so it cannot be used in a @foreach. As you said you have an image collection relative to the first loop item, you need to use the property that returns that collection.

  • Okay, but how do I do that? Thank you

  • 1

    In his class of Model, which contains the property Thumb needs to be, for example: public List<Imagem> Thumb {get; set;}. This list will need to be instantiated, of course, and filled in with the instances of Imagem, of course, for iteration to occur.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.