From Controller I am passing a list of AccountNumbers using ViewBag to the View, and this is running well
Controller Code:
List<AccountNumberSum> my_output_list = new List<AccountNumberSum>();
my_output_list.Add(new AccountNumberSum {
account_number = oo.CreditAccountNumber,
total_amount = item1.Amount.Value
});
var grouped_data = my_output_list.GroupBy(x => x.account_number)
.Select(x => new { account_number = x.Key, total_amount = x.Sum(y=> y.total_amount) })
.ToList();
ViewBag.grouped_data = grouped_data.Count();
And View Code For this is :
@if (ViewBag.grouped_data != null)
{
<div class="tb">
<table id="table_id" class="display" style="width:100%">
<thead>
<tr>
<th>
Sl.No
</th>
<th>
Account Number
</th>
<th>
Total Amount
</th>
</tr>
</thead>
@foreach (var item in ViewBag.grouped_data.GetType().GetProperties())
{
<tr>
<td>
@item.account_number
</td>
<td>
@item.total_amount
</td>
</tr>
}
</table>
</div>
} I am getting the following error: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Cannot implicitly convert type 'int' to 'System.Collections.IEnumerable''. I want to show account numbers,Total_amount in Table in view using ViewBag.