I\'m working in asp.net core inside a MVC application. I\'m using the scaffolding feature that creates the views and controller based on a model. Below is the model that i
First this is you must have a public accessor to your ShoppingList class.
So, public class ShoppingList
.
Next is your view will need the following changes.
@model ShoppingList
@Model.Name
@Model.ShoppingListId
foreach(var item in Model.ListItems)
{
@item
}
So, the above code is roughly what you are looking for. In Razor you can accessor the models variables by using the @model at the top of the view. But one thing you need to note is if your model is in a subfolder you'll need to dot into that.
Here's an example: @model BethanysPieShop.Models.ShoppingCart
.
Here BethanysPieShop is my project name, Models is my folder the ShoppingCart class is in.