Why is this Html Helper code so nasty? I specify the ID to bind to in the linq expression, but have to do it again in the SelectList? Is there a better way to do this but still keep RelationshipTypes as an IEnumerable?
Model:
public class ResponderGuestsModel
{
public List<GuestInfo> Guests { get; set; }
public IEnumerable<Business.RelationshipType> RelationshipTypes { get; set; }
public class GuestInfo
{
public int? RelationshipTypeId { get; set; }
}
}
}
View:
@for (int i = 0; i < Model.Guests.Count; i++)
{
@Html.DropDownListFor(model => model.Guests[i].RelationshipTypeId, new SelectList(Model.RelationshipTypes, "RelationshipTypeId", "Name", Model.Guests[i].RelationshipTypeId), "", new { @class = "form-control" })
}