Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, the problem is with the way you are populating your view model. You must initialize the lists and then add items to them:</p> <pre><code>private MenuViewModel LoadViewModel(int menuNameID) { List&lt;Category&gt; returnedCategories = GetAllMenuDataModel.GetAllMenuItemsByCategory(menuNameID); MenuViewModel vmMenu = new MenuViewModel(); vmMenu.CategoryList = new List&lt;CategoryViewModel&gt;(); foreach (Category category in returnedCategories) { CategoryViewModel vmCategory = new CategoryViewModel { CategoryID = category.categoryId, CategoryTitle = category.categoryTitle }; vmCategory.MenuItemList = new List&lt;MenuItemViewModel&gt;(); foreach (MenuItem menuItem in category.MenuItems) { MenuItemViewModel vmMenuItem = new MenuItemViewModel { Title = menuItem.itemTitle, Description = menuItem.itemDescription, Note = menuItem.itemNote }; vmMenuItem.PriceList = new List&lt;PriceViewModel&gt;(); foreach (Price price in menuItem.Prices) { PriceViewModel vmPrices = new PriceViewModel(); switch (price.MealType.mealName.ToLower()) { case "lunch": if (price.ServingSize.sizeName == "Regular") { vmPrices.PriceValueLargeLunch = price.priceValue; } if (price.ServingSize.sizeName == "Small") { vmPrices.PriceValueLargeLunch = price.priceValue; } if (price.ServingSize.sizeName == "Large") { vmPrices.PriceValueLargeLunch = price.priceValue; } break; case "dinner": if (price.ServingSize.sizeName == "Regular") { vmPrices.PriceValueLargeLunch = price.priceValue; } if (price.ServingSize.sizeName == "Small") { vmPrices.PriceValueLargeLunch = price.priceValue; } if (price.ServingSize.sizeName == "Large") { vmPrices.PriceValueLargeLunch = price.priceValue; } break; case "takeOut": if (price.ServingSize.sizeName == "Regular") { vmPrices.PriceValueLargeLunch = price.priceValue; } if (price.ServingSize.sizeName == "Small") { vmPrices.PriceValueLargeLunch = price.priceValue; } if (price.ServingSize.sizeName == "Large") { vmPrices.PriceValueLargeLunch = price.priceValue; } break; } vmMenuItem.PriceList.Add(vmPrices); } vmCategory.MenuItemList.Add(vmMenuItem); } vmMenu.CategoryList.Add(vmCategory); } return vmMenu; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload