Thank you again to Richard and Gerry.
After additional research, I found that this issue was addressed in stack
overflow.
Thanks to GAC for asking the question and to enet for answering.
I will try to summarize the answer, but you should check out the original at
.net core - Error in foreach loop when displaying an ICollection of a one-to-many data model - Stack Overflow[
^]
The problem was in the Edit page (sorry, it was not included in the problem statement).
In the Edit page, the recipe class was
o defined AND instantiated,
o retrieved from the server via call to http.GetFromJsonAsync,
o and passed to the EditForm component.
Between retrieving the recipe class and passing the parameter, the ICollection was lost.
What is needed was to change the definition of the recipe class to OMIT instantiating it to null. It is a quirk of the rendering of the Blazor page. See the code below
@page "/recipe/edit/{recipeId:int}"
@inject HttpClient http
@inject NavigationManager uriHelper
@inject IJSRuntime js
<h3>Edit</h3>
<Form ButtonText="Update" recipe="recipe"
OnValidSubmit="@EditRecipe" />
@code {
[Parameter] public int recipeId { get; set; }
Recipe recipe;
protected async override Task OnParametersSetAsync()
{
recipe = await http.GetFromJsonAsync<Recipe>($"api/recipe/{recipeId}");
}
async Task EditRecipe()
{
await http.PutAsJsonAsync("api/recipe", recipe);
await js.InvokeVoidAsync("alert", $"Updated Successfully!");
uriHelper.NavigateTo("recipe");
}
}