asp.net mvc3 viewbag 穿传参bug

以前使用viewbag传值,一直没什么问题。

今天有一个有点复杂的传值就发现了问题请先看代码

public ActionResult About()

        {

            ViewBag.act

                  = from t in db.Articles

                      group t by t.Type into pgroup

                      select pgroup;

    foreach (var m in ViewBag.act)

            {

                string tp = m.Key;

                int coun = m.Count();

            }

        }

问题就是M.key 中值不能正常显示

public ActionResult About()

        {

            var ttt = from t in db.Articles

                      group t by t.Type into pgroup

                      select pgroup;

    foreach (var m in ttt )

            {

                string tp = m.Key;

                int coun = m.Count();

            }

        }

当使用弱类型是m.key的值则可以正常显示。

迫于无奈只好用强类型去实现类似功能:

 

 

 

 

你可能感兴趣的:(asp.net)