控制器中代码:
var list = context.Says.Join(
context.Users,
a => a.UserId,
b => b.Id,
(a, b) => new
{
UserName = b.Name,
Content = a.Content,
CreateTime = a.CreateTime,
Id = a.Id
}).OrderByDescending(a => a.CreateTime).ToList(); ViewData["data"] = list;
return View();
视图中代码:
dynamic data=ViewData["data"];
<p>@item.GetType().GetProperty("UserName").GetValue(item, null)</p>
不过好像不推荐这么写,动态解析性能肯定差了。
老赵文章:
使用Mono.Cecil辅助ASP.NET MVC使用dynamic类型Model
aparche文章: