0

我正在尝试加入两个表。用户和记分牌

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) }

最后一行返回错误“表达式树可能不包含动态运算符”,我不确定这意味着什么。

4

1 回答 1

2

您得到的错误是因为 publicIEnumerable<dynamic> Scoreboards 是动态的, @foreach (var item in Model.Scoreboards)而 lambda 表达式不支持动态

于 2013-05-13T01:56:59.643 回答