I have successfully used an sql inner join with two tables in webforms to join two tables to a single html unordered list.
I am using Asp.net MVC 5 Entityframework 6
I am trying to join the same two tables in MVC to again output a single html unordered list.
The first table is named team with the column id the second table is named teamgallery with a column teamID. The values of team.id and teamgallery.teamID are equal.
in the controller:
dynamic dmodel = new ExpandoObject();
dmodel.Teamre = (from pd in db.teams
join od in db.teamgalleries on pd.id equals od.teamID
where pd.Catresales == "yes"
select new
{
pd.id,
pd.name,
od.picture
}).ToList();
return View(dmodel);
In the view:
<ul>
@foreach (var teamre in Model.Teamre)
{
<li>
@teamre
</li>
}
</ul>
In the web browser this returns a list like this:
{ id = 1, name = John Doe, picture = picture1.jpg }
{ id = 2, name = Jane Doe, picture = picture2.jpg }
If I change the razor code to display just the names:
@teamre.name
I'll receive this error
Server Error in '' Application. 'object' does not contain a definition for 'name'
The error shows even if I write
name = pd.name,
dynamic
, there is no reason for it here, just usevar
. Also, how isTeamre
defined in classExpandoObject
?