Asp.net mvc 3 ViewBag而不是DropDownList中的IEnumerable
我传入了一个ViewBag,其中包含一个类的ID和标题(我们称之为游戏)。我正在尝试使用ViewBag的内容而不是枚举创建Html.DropDownList 现在,我有以下不正确的代码:Asp.net mvc 3 ViewBag而不是DropDownList中的IEnumerable,asp.net-mvc-3,drop-down-menu,ienumerable,viewbag,Asp.net Mvc 3,Drop Down Menu,Ienumerable,Viewbag,我传入了一个ViewBag,其中包含一个类的ID和标题(我们称之为游戏)。我正在尝试使用ViewBag的内容而不是枚举创建Html.DropDownList 现在,我有以下不正确的代码: Html.DropDownList("GameID", new SelectList(from IEnumerable<Games> game in Enum.GetValues(ViewBag.Games) select new { value = ViewBag.Games.ID, name
Html.DropDownList("GameID", new SelectList(from IEnumerable<Games> game in
Enum.GetValues(ViewBag.Games) select new { value =
ViewBag.Games.ID, name = ViewBag.Games.Title}, "value", "name", Model.Content.GameID))
Html.DropDownList(“GameID”),新的选择列表(来自IEnumerable游戏中的
Enum.GetValues(ViewBag.Games)选择新{value=
ViewBag.Games.ID,name=ViewBag.Games.Title},“值”,“名称”,Model.Content.GameID))
我知道我需要替换from和in变量,但我不知道用什么替换它们。有什么想法吗?谢谢。如果您已经将游戏的ID和标题字段保存在ViewBag中,为什么您不能这样做呢
@Html.DropDownList("GameID", new SelectList(ViewBag.Games, "ID", "Title"))
如果您已经在ViewBag中设置了游戏的ID和标题字段,为什么不这样做呢
@Html.DropDownList("GameID", new SelectList(ViewBag.Games, "ID", "Title"))
看这里看这里