我正在尝试加入两个表。用户和记分牌
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) }
最后一行返回错误“表达式树可能不包含动态运算符”,我不确定这意味着什么。