I have a code that I've written which looks like this:
ViewBag.Items = user.Items.GroupBy(x => x.ItemId).Select(pr => new
{
ItemId = pr.Key,
ImageURL = pr.Select(x=>x.ImageURL).FirstOrDefault(),
Title = pr.Select(x=>x.Title).FirstOrDefault(),
Sales = pr.Select(x=>x.Transactions.Sum(y=>y.QuantitySold))
}).ToList();
As you can see it's a list of anonymous objects... What I'm trying to do now is to bind these values into my already existing view like this:
<tbody>
@if (ViewBag.Items != null)
{
foreach (var item in ViewBag.Items)
{
<tr>
<td><img src="@item.ImageURL" /></td>
<td>@item.Title</td>
<td>@item.Sales</td>
</tr>
}
}
</tbody>
But I'm getting this error:
Additional information: 'object' does not contain a definition for 'ImageURL'
And for other properties as well...
How can I fix this, but to in same time avoid creating extra class that would make the view strongly types.. Can someone help me out ?