C#C
C#4y ago
50 replies
framoz

ASP NET MVC, can't show Collection in View, VS say it is null

Hello, I'm working on a MVC Project for a film website (IMDb like). I have a User class and a Person class with a many to many relationship and want to show a User table in this Person detail view.

*@ This is the code inside the cshtml, that I tried using to show the data in the view
<table class="table table-bordered table table-striped" style="width:100%">
        <thead>
            <tr>
                <th>
                    Users
                </th>
            </tr>
        </thead>
        <tbody>
            @if (Model != null && Model.Users != null)
            {
                @foreach (var obj in Model.Users)
                {
                    <tr>
                        <td>
                            @obj.Name
                        </td>

                    </tr>
                }
            }
        </tbody>
    </table>
image.png
Was this page helpful?