My code is trying to enumerate over a (currently empty) list of movies. When it gets to the ForEach
loop it blows up with the stated error.
I would think it would just not iterate (moveNext()). How can I fix this behavior so that it will just display an empty list when the collection is blank
@using System.Collections.Generic
@using Microsoft.EntityFrameworkCore.Metadata.Internal
@using x.Models
@model IEnumerable<x.Models.Movie>
@{
ViewData["Title"] = "MovieView";
}
<h2>MovieView</h2>
<p>
<a asp-action="List">Movie List</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Title)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
<th>
@Html.DisplayNameFor(model => model.Genre)
</th>
<th>
@Html.DisplayNameFor(model => model.Year)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (Movie item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.Genre)
</td>
<td>
@Html.DisplayFor(modelItem => item.Year)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
<a asp-action="Details" asp-route-id="@item.Id">Details</a> |
<a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
</td>
</tr>
}
</tbody>
</table>