I am trying to return records from db and group by Transaction Date so I can see only one record for each specific date in the view if I have multiple transactions in the same day. I did the query and it is working fine but the view is not displaying the result and I am getting an error:
The model item passed into the dictionary is of type 'System.Collections.Generic.List
1[System.Linq.IGrouping
2[System.DateTime,TouchlessWeb.Models.ClientAccounting]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[TouchlessWeb.Models.ClientAccounting]'.
My controller Code:
var query = db.clientAccountings.Where(u => u.OrgId == id).GroupBy(o => o.TransDate);
return View(query.ToList());
and My View:
@model IEnumerable<TouchlessWeb.Models.ClientAccounting>
@foreach (var user in Model)
{
<tbody>
<tr>
<td>@user.TransDate </td>
<td>RM @user.Amount</td>
<td>
@if (user.AccType == 1)
{
<span class="text-danger">Seasonal</span>
}
@if (user.AccType == 2)
{
<span>Occasional</span>
}
</td>
<td>@user.TransID</td>
<td>Not Paid</td>
<td>@user.RefNo</td>
</tr>
</tbody>
}
I am new to MVC, I hope you can help me. Thanks