Cheers, here is what I did:
public class BinStockModel
{
public string Name { get; set; }
public double Total { get; set; }
}
and then in my controller:
var binstock = db.Bin_Material
.OrderBy(m=>m.Material.Name)
.GroupBy(m => m.Material.Name)
.Select(
g => new {
Name = g.Key,
Total = g.Sum(m => m.Qty)
});
var res = new List<binstockmodel>();
foreach (var item in binstock)
{
res.Add(new BinStockModel{ Name = item.Name, Total = (double)item.Total });
}
return View(res);</binstockmodel>
And then in my View:
@model IEnumerable<storemanager.models.binstockmodel>
@foreach (var item in @Model)
{
bintotal = bintotal + @item.Total;
<tr>
<th>@item.Name</th>
<td style="text-align: right;">@item.Total</td>
</tr>
}
</storemanager.models.binstockmodel>
Worked a charm.