// 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”的定义
为什么?我能做什么?
发布于 2011-04-06 15:38:33
匿名类型被编译成内部类。
dynamic使用的标准绑定器将只绑定到公共类的公共成员。
因此,不能将它与来自不同程序集的匿名类型一起使用。
有关更多信息,请参见这里。
https://stackoverflow.com/questions/5568453
复制相似问题