Create dynamic forms that grow at run time

前端 未结 2 934
独厮守ぢ
独厮守ぢ 2020-12-19 10:04

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

2条回答
  •  执念已碎
    2020-12-19 10:52

    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.

提交回复
热议问题