MVC “create view” when there is one to many relationship in model

后端 未结 2 766
谎友^
谎友^ 2021-01-01 08:01

My model is simple, one client can have many phone numbers :

I have represented this in Entity Framework\"\"

2条回答
  •  轮回少年
    2021-01-01 08:23

    For the collection you can use something like this:

    @for(int i = 0; i < Model.PhoneNumbers.Count; i++)
    {
       
    @Html.EditorFor(model => model.PhoneNumbers[i]) @Html.ValidationMessageFor(model => model.PhoneNumbers[i])
    }

提交回复
热议问题