Looping through view Model properties in a View

后端 未结 7 2298
南旧
南旧 2020-12-12 22:04

I have a painfully simple view model

public class TellAFriendViewModel
{
    public string Email1 { get; set; }
    public string Email2 { get; set; }
    pu         


        
7条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 22:22

    Perhaps like this?

    public class TellAFriendViewModel
    {
     List Emails { get; set; }
    
     public TellAFriendViewModel()
     {
      Emails = new List(5);
     }
    }
    
    @using (Html.BeginForm()){
     @Html.AntiForgeryToken()
    
     @for(int count = 0 ; count < model.Emails.Count; count++)
     {
      @Html.TextBoxFor(vm => vm.Emails[count])
     }
    }
    

提交回复
热议问题