标签:
1、将匿名类型赋给ViewBag然后通过反射读取
@foreach (var i in @ViewBag.Ages) { <div style="border:1px solid black;">@i.GetType().GetProperty("Age").GetValue(i,null)</div> }
2、借助JSON.NET,不过在RAZOR视图中失去了强类型的感知
List<Test> source = new List<Test> { new Test{Age=20,Name="阿猫"}, new Test{Age=30,Name="阿狗"}, new Test{Age=1,Name="王二麻子"} }; var r = source.Select(t => new { Age = t.Age * 5 }).ToList(); return View(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(r)));
ASP.NET MVC3 匿名类型视图模型无法识别的解决方案
标签:
原文地址:http://blog.csdn.net/echoshinian100/article/details/43195813