为什么这个Html Helper代码如此讨厌?我在linq表达式中指定要绑定的ID,但是必须在SelectList中再次执行此操作?有没有更好的方法来做到这一点,但仍然将RelationshipTypes保持为IEnumerable?
型号:
public class ResponderGuestsModel
{
public List<GuestInfo> Guests { get; set; }
public IEnumerable<Business.RelationshipType> RelationshipTypes { get; set; }
public class GuestInfo
{
public int? RelationshipTypeId { get; set; }
}
}
}
查看:
@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" })
}