Controller代码:
public ActionResult TupleTest() { LinqDBEntities db = new LinqDBEntities(); dynamic data = db.StuInfo.ToList().Select(s => Tuple.Create(s.StuNum, s.StuName, s.StuAge,s.StuSex, s.ClassID)); ViewData["data"] = data; return View(); }
在Controller中把要传递的数据通过Tuple.Create封装数据
View代码:
@{ dynamic dd = ViewData["data"]; foreach (var item in dd) { Response.Write(item.Item1+"-"+item.Item2+"-"+item.Item3+"-"+item.Item4+"-"+item.Item5+"<br>"); }
}