我正在尝试连接两个表。用户和计分板
视图模型> 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) }
最后一行返回错误"表达式树可能不包含动态操作符",我不确定这是什么意思
您看到的错误是因为公共IEnumerable<dynamic> Scoreboards
是动态的,而动态的@foreach (var item in Model.Scoreboards)
不支持lambda表达式