This is the controller:
public ActionResult Index()
{
var result = from u in myContext.Users
join g in myContext.Groups
on u.gid equals g.id
select new {
u.username,
g.name
};
return View(result );
}
This is the View
@model IEnumerable<eTravel1.Models.User>
...
@Html.DisplayNameFor(model => model.username)
@Html.DisplayNameFor(model => model.name)
..
The returned anonymous data is not compatible in the View.
I would really apreciate it if someone could give some advice. Thanks
You should create a ViewModel Class like this:
Create an object of that class:
And finally, pass this object to your view the same way:
In your View, you should expect this exact same data type:
I strongly recommend you to read this stackoverflow question about the “ViewModel Best Practices”.
Hope it helps!