// 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行: '對象' 不包含定義爲 '計數'
爲什麼?我能做什麼?
該錯誤與剃刀本身無關。 – SLaks 2011-04-06 15:38:59
@SLaks,正確,你的回答很好地解釋了它。感謝您指出了這一點。這清除了我的困惑。我會更新我的答案,只保留不使用動態的相關部分。 – 2011-04-06 15:51:06