从控制器我传递了一个使用viewbag的帐号列表到视图,运行良好
控制器代码:
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();
查看代码为:
@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>
}我收到以下错误:microsoft.csharp.runtimebinder.runtimebinderexception:'无法将类型'int'隐式转换为'system.collections.ienumerable'。我想显示帐户号码,总金额在表中查看使用viewbag。
1条答案
按热度按时间iszxjhcz1#
因为你在传递计数,它是int,你把它当作
IEnunerable
在视野中。不用申请就通过Count()
.