Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 ViewBag而不是DropDownList中的IEnumerable_Asp.net Mvc 3_Drop Down Menu_Ienumerable_Viewbag - Fatal编程技术网

Asp.net mvc 3 ViewBag而不是DropDownList中的IEnumerable

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

我传入了一个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 = 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"))
看这里看这里