Abdalla Omran

Abdalla Omran

  • NA
  • 334
  • 29.1k

Nasted foreach in ViewModel

Sep 10 2021 2:52 PM

I would like to dispaly the Name Ben only as Admin and the Name User1 as User but it gives me both of them in table see picture & the code what I have tried please : 


@model ePizzaHub.WebUI.ViewlModel.AdminRoleView
@{
    ViewData["Title"] = "Index";
}

<h1>Admin Dashboard</h1>

<table class="table">
    <thead>
        <tr>
            <th>
                Name
            </th>
            <th>
                Email
            </th>
            <th>
                Admin
            </th>

        </tr>
    </thead>
    <tbody>

        @foreach (var item in Model.Users)
        {

            <tr>
                <td>
                    @item.Name
                </td>
                <td>
                    @item.Email
                </td>
                @foreach (var role in Model.Roles)
                {

                    <td>
                        @role.Name

                    </td>

                }

            </tr>
        }
    </tbody>
</table>


Answers (3)