EFCore+Razor Pages: nested foreach loop iterating over .included dataset returning zero results

asp.net-core-mvc c# entity-framework-6 linq razor-pages

Accepted Answer

I get the impression that you are simply iterating over the first Model's ChildTable elements each time.

Modify this:

@foreach (var relatedItem in Model.ParentTable[0].ChildTable)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => relatedItem.ChildField1)
        </td>
        <td>
            @Html.DisplayFor(modelItem => relatedItem.ChildField2)
        </td>
    </tr>
}

To:

@foreach (var relatedItem in item.ChildTable)
{
    <tr>
        <td>
            @Html.DisplayFor(ri => relatedItem.ChildField1)
        </td>
        <td>
            @Html.DisplayFor(ri => relatedItem.ChildField2)
        </td>
    </tr>
}
0
3/27/2018 5:34:02 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow