I have a Model with a List of Transactions. Each Transaction has Category and Transaction Amount.
In my view page, I am creating a table from the Model which shows in each row of the table:
Category1 - SumofTransactionAmounts1
Category2 - SumofTransactionAmounts2
Category3 - SumofTransactionAmounts3
I am able to achieve this. However, how can i order the rows by ascending/ descending order of SumofTransactionAmounts?
@foreach (var item in Model.MyTransactions.groupby(x => x.Category).ToList())
{
<tr>
<td>@item.key</td>
<td>@Model.MyTransactions.Where(x => x.Category == item.key).ToList().Sum(x => x.TransactionAmount)</td>
</tr>
}