注意是mvc的dropdownlist,也就是将泛型转换成selectlist类型,请问怎么转。谢谢了 

解决方案 »

  1.   

            public ActionResult Create()
            {
                ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name");
                ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name");
                return View();
            }             @Html.DropDownList("GenreId", "Please Select")
                @Html.ValidationMessageFor(model => model.GenreId)
      

  2.   

    db.Genres?是什么?是不是Linq查询啊,linq查询出来的好像也是list<T>吧,但是我把List<T>类型的返回值放在那里不行,        public ActionResult Index()
            {
                Models.Ma_Vocation_Repository mo=new Models.Ma_Vocation_Repository ();
                List<Models.Ma_Vocation> ma = new List<Models.Ma_Vocation>();
                ma=mo.SelectAll();
                var selist = new SelectList(ma,"Id","Name");
                ViewData["mv"] = selist;
                return View();
            }
    提示:不存在具有键“mv”的“IEnumerable<SelectListItem>”类型的 ViewData 项。
    小弟初学,见笑……
      

  3.   

    唉~我没用Linq ,自己写的泛型类,郁闷啦,还有人不,给个解决啊,救命啊