DropDownList 中使用 ViewBag 代替 IEnumerable
我传入了一个 ViewBag,其中包含一个类(我们将其称为“游戏”)中的 ID 和标题。我正在尝试使用 ViewBag 的内容而不是 Enum 来制作 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))
我知道我需要替换 from 和 in 变量,但我不知道用什么替换它们。有什么想法吗?谢谢。
I have a ViewBag passed in consisting of IDs and Titles from a class (we will call it Games). I am trying to make an Html.DropDownList using the contents of the ViewBag instead of an Enum.
Right Now, I have the following code which is incorrect:
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))
I know that I need to replace the from and the in variables but I do not know what to replace them with. Any ideas? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您已经将游戏的 ID 和标题字段放在 ViewBag 中,为什么不直接这样做呢?
If you already have the Game's ID and Title fields being past down in the ViewBag, why could you not just do this?