I am doing a left outer join in Entity Framework and sending the output in a ViewBag
to display in a table. However, nothing is displayed in a View
. My code is below.
var clients = db.Client
.Include("ClientInformation")
.Where(t => t.IsApplicationRegistered == false)
.Take(20);
var q = (from c in clients
join a in db.Agent
on c.AgentUserId equals a.AgentUserId into jointable
from x in jointable.DefaultIfEmpty()
select new
{
c.ClientId,
c.ClientInformation.FirstName,
c.ClientInformation.FamilyName,
c.ClientInformation.Address,
AgentFirstName = x.FirstName,
AgentLastName = x.LastName
}).ToList();
ViewBag.clients = q;
This retrieves the results (I can see them via IntelliSense during debug) but the view does not display anything. The sample view is below.
@foreach (dynamic item in ViewBag.clients)
{
<tr>
<td>@item.FirstName @item.FamilyName</td>
<td>@item.Address</td>
<td>@item.AgentFirstName @item.AgentLastName</td>
</tr>
}
Any ideas? Thanks.
UPDATE:
Inside the View
I get an exception
'object' does not contain a definition for 'FirstName'
However, I can clearly see that it is there, when I hover over item
inside foreach
loop.