0

您好,我是 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; }
    }
4

1 回答 1

0

最简单的方法是

@Html.DropDownListFor(
    x => x.SelectedRentalId,
    Model.Rentals
)

更好地了解如何使用它,包括选择部分,se Darin's answer

https://stackoverflow.com/a/6807331/28004

于 2012-12-25T22:59:07.747 回答