Enumerate a list in a list-passing model

This is the model that I am moving to my mind as a list:

    public class DogContentPage : ContentPage
    {

    public string Name { get; set; }
    public string Age { get; set; }
    public bool IsFemale { get; set; }

    public string Image { get; set; }
    public List<string> Merits { get; set; }
}

View:

@model List<EmmysBlog_Core.Models.Dog.DogContentPage>

As you can see, the model contains a list of rows (Merits). I have problems going through the Merit list. I suspect that for this is that I am passing the model as a list. Is it possible for me to go through virtues?

This attempt:

@foreach (var item in Model)
       {
          <li>@item.Merits</li>
       }

Only gives me a list: System.Collection.Generic ...

Do I need to change the way the model is passed to the view, or is there another way to build a loop to access values ​​in Merits?

View:

@foreach (var dogs in Model.Where(o => o.IsFemale))
                {
                    <div class="media">
                        <div class="col-md-4">
                            <a href="#">
                                <img src="@dogs.Image" style="width: 100%">
                            </a>

                        </div>

                        <div class="col-md-4" style="text-align: center;">
                            <a href="#"><h3 class="media-heading">@dogs.Name</h3></a>
                            @Html.ActionLink("Stamtavla", "Dog", "Home", new { pageId = dogs.Id }, null)

                        </div>
                        <div class="col-md-4">
                            <ul>
                                @foreach (var item in Model)
                                {
                                     foreach (var merit in item.Merits)
                                     {
                                         <li>@merit</li>
                                     }
                                }

                            </ul>

                        </div>
                    </div>
                }
                </div>
            </div>
+4
source share
2 answers

Just add more foreachfor the list.Merits

@foreach (var item in Model)
   foreach (var merit in item.Merits)
   {
      <li>@merit</li>
   }

Update

:

   foreach (var merit in dogs.Merits)
   {
       <li>@merit</li>
   }
+4

- :

@foreach (var item in Model)
   {
     <ul> 
     @foreach(var merit in item.Merits)
     {
         <li>@merit</li>
     }
     </ul>
   }
+1

Source: https://habr.com/ru/post/1545121/


All Articles