In your Recipie
model you have have a List<RecipieLine>
property which one would assume is to maintain one or more RecipieLine
model objects. In your RecipieLineViewModel
you have two separate IEnumerable
collections exposing your Recipie
and RecipieLine
objects.
In your actual view, you are iterating over your Recipie
collection:
@foreach (Recipe recipe in Model.Recipes)
Looks good, however, the following line is your issue:
foreach (RecipeLine recipeLines in Model.RecipeLines)
This enumerates over the RecipieLine
model objects stored in your RecipieLineViewModel
RecipieLine
collection, however, it currently has no way of knowing which Recipie
you are currently enumerating in your outer foreach
.
You either want to provide a where
LINQ clause of some sort using the data available to you from the current Recipie
object enumeration, or alter the inner foreach
to use the current Recipie
enumeration rather than the Model
.
Update
For completeness, here is an example of how to use the current Recipe
object enumeration to access its associated RecipieLine
s:
@forech (var recipie in Model.Recipies)
{
<div>@recipe.RecipeName</div>
<div>@recipe.RecipeInstructions</div>
foreach (var recipieLine in recipie.RecipieLines)
{
<div class="row">
<div class="large-12 columns">
// Do something with recipieLine here
</div>
</div>
}
}
The above would be my preferred method as it is more efficient that performing a LINQ query each enumeration, and removes the IEnumerable<RecipieLine>
from your ViewModel
which is effectively duplicate code.