【发布时间】:2014-06-18 12:34:08
【问题描述】:
我想传递我的查询结果,然后我想迭代我的网络表单。这是我的清单
var recentGames = game.OrderByDescending(c => c.OutcomeDateTime)
.Take(3);
现在我正试图把它放在 ViewData 中
ViewData["Elements"] = recentGames;
然后尝试循环查看我的视图上的 ViewData["Elements"]
List<Games> t = (List<Games>)ViewData["Elements"];
recentGames 具有 Games 类属性,但我无法在我的视图(Web 表单)中初始化 Games 类并出现错误。有没有更好的方法将列表传递给查看,然后遍历循环以打印简单???
【问题讨论】:
标签: c# asp.net-mvc linq asp.net-mvc-3 asp.net-mvc-4