我正在尝试加入两张桌子。用户和记分板
的ViewModels> ScoreboardVM.cs
public class ScoreboardVM
{
public IEnumerable<dynamic> Scoreboards { get; set; }
}
控制器
var db = new GameDBDataContext();
var userList = (from s in db.Scoreboards
join u in db.Users on s.User equals u.UserId
select new { UserName = u.UserName }).Take(5);
var viewModel = new ScoreboardVM();
viewModel.Scoreboards = userList;
return View(viewModel);
查看
@model Project.ViewModels.ScoreboardVM
@foreach (var item in Model.Scoreboards) {
@Html.DisplayFor(model => item.UserName) }
最后一行返回错误“表达式树可能不包含动态运算符”,我不确定这意味着什么。
答案 0 :(得分:2)
您获得的错误是因为公共IEnumerable<dynamic> Scoreboards
是动态的,并且lambda表达式不支持动态@foreach (var item in Model.Scoreboards)