Reputation: 101
I'm trying to join two tables. User and Scoreboard
ViewModels>ScoreboardVM.cs
public class ScoreboardVM
{
public IEnumerable<dynamic> Scoreboards { get; set; }
}
Controller
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);
View
@model Project.ViewModels.ScoreboardVM
@foreach (var item in Model.Scoreboards) {
@Html.DisplayFor(model => item.UserName) }
The last line returns the error "An expression tree may not contain a dynamic operator" and I'm not sure what that means.
Upvotes: 0
Views: 1164
Reputation: 13579
The error you aree getting is because the public IEnumerable<dynamic> Scoreboards
is dynamic and @foreach (var item in Model.Scoreboards)
which is dynamic is not supported by the lambda expression
Upvotes: 2