This is in my controller:
public ActionResult Index()
{
var groupJoin = from d in db.tblParent1
join e in db.tblParent2 on d.parent1ID equals e.parent1ID
select new
{
parent1ID = d.parent1ID,
parent1Name = d.parent1Name,
parent2ID = e.parent2ID,
parent2Name = e.parent2Name,
};
ViewBag.groupJoin = groupJoin.ToList();
return View();
}
This is my view:
@foreach (var item in ViewBag.groupJoin)
{
<tr>
<td>
@item.parent1Name
</td>
<td>
@item.parent2Name
</td>
</tr>
}
I get this error :
object does not contain a definition for
parent1Name
when replacing @item.parent1Name
with @item
. It displays the whole row like this in the web
{ parent1ID = 1, parent1Name = master , parent2ID = 2, parent2Name = child }
How can I specify a column?