我的剃刀页面中有这个IEnumerable方法。
@if (Orders.Any())
{
<table class="table table-bordered">
<thead>
<th>Driver Name</th>
<th>Delivery Orders</th>
</thead>
<tbody>
@foreach(var objOrders in Orders)
{
<tr>
<th>
@objOrders.Driver.UserName
</th>
<th>
@objOrders.Driver.FullName.Count()
</th>
<td>
</td>
</tr>
}
</tbody>
</table>
}
哪个是
private IEnumerable<OrderDTO> Orders { get; set; } = new List<OrderDTO>();
private bool IsLoading { get; set; } = true;
public async Task SearchDate()
{
Orders = await _orderRepository.GetDate(DateValue);
}
private async Task LoadOrders()
{
IsLoading=true;
StateHasChanged();
await SearchDate();
//Orders = await _orderRepository.GetDate(date);
IsLoading = false;
StateHasChanged();
}
在这里
public async Task<IEnumerable<OrderDTO>> GetDate(DateTime date)
{
if (date != null)
{
return _mapper.Map<IEnumerable<Order>, IEnumerable<OrderDTO>>
((IEnumerable<Order>)_db.Orders.Where(u => u.DeliveryDate == date));
}
else
{
return _mapper.Map<IEnumerable<Order>, IEnumerable<OrderDTO>>(_db.Orders);
}
}
目前,显示器有点像
|Driver Name | Number Delivery Orders |
| :--- | :----: |
| 1 | 1 |
| 1 | 1 |
| 2 | 1 |
|Kim1 | 4 |
我想像这个一样显示
|Driver Name | Number Delivery Orders |
| :--- | :----: |
| 1 | 2 (Occurrences) |
| 2 | 1 (Occurrences) |
|Kim1 | 1 (Occurrences) |
我知道现在Count()
方法正在计算驱动程序名称的长度,但我如何对其进行编码,使其返回出现的驱动程序名称。
谢谢大家。
@foreach(var objOrders in Orders
.GroupBy(u => u.Driver.FullName)
.Select(group => new {
Count= group.Count(),
Key=group.Key }
)
)
设法做到这一点。感谢@Martin Costello