次のようなもの:
public class MyViewModel
{
public int Selected { get; set; }
public List<Person> All { get; set; }
public List<Person> Exclude { get; set; }
// Create selectlist of items which are not in exclude list
public SelectList GetSelectList
{
get
{
var r = All.Where(q => !Exclude.Any(p => p.ID == q.ID)).OrderBy(p => p.Name).ToList();
return new SelectList(r, "ID", "Name", Selected);
}
}
public MyViewModel()
{
All = new List<Person>();
Exclude = new List<Person>();
}
}
ビューで:
@Html.DropDownListFor(model => model.Selected,Model.GetSelectList)