【发布时间】:2011-04-06 14:56:13
【问题描述】:
// this function working perfectly
public dynamic CountTable()
{
return (from t in db.Users
group t by t.Type into g
select new
{
type = g.Key,
count = g.Count(),
ActiveGroups = (from t in g group t by t.Active into ag select new { active = ag.Key, count = ag.Count() })
}).ToList();
}
// and this loop working in MVC Controller
foreach (dynamic uct in ur.CountTable())
{
int x = uct.count;
}
但不能在模板中工作:
Line 12: @foreach (dynamic uct in ViewBag.ur.CountTable())
Line 13: {
Line 14: int adet = uct.count;
Line 15: }
第 14 行:“object”不包含“count”的定义
为什么?我能做什么?
【问题讨论】:
标签: linq asp.net-mvc-3 dynamic c#-4.0 razor