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>
source
share