您好我是mvc 3的新手,我需要一些指针/帮助填充下拉列表。我有3个类是我的域类。基本上我想要做的是制作一个下拉列表,其中将填充特定成员租用的电影。最简单的方法是什么?是使用ViewBag还是制作ViewModel?
public class Member
{
public virtual int MemberId { get; set; }
public virtual long PersonalNr { get; set; }
public virtual string Name { get; set; }
public virtual string LastName { get; set; }
public virtual List<Rental> Rentals { get; set; }
}
public class Movie
{
public virtual int MovieId { get; set; }
public virtual string Name { get; set; }
public virtual bool IsInStock { get; set; }
}
public class Rental
{
public virtual int RentalId { get; set; }
public virtual int MovieId { get; set; }
public virtual Movie Movie { get; set; }
public virtual int MemberId { get; set; }
public virtual Member Member { get; set; }
public DateTime startDate { get; set; }
public DateTime dueDate { get; set; }
}
答案 0 :(得分:0)
最简单的方法是
@Html.DropDownListFor(
x => x.SelectedRentalId,
Model.Rentals
)
了解如何使用它,包括选择部分se Darin's answer