这是我的模型:
public class ViewInvoice
{
public string ClientLocation { get; set; }
public List<DetailsGroup> Details { get; set; }
public class DetailsGroup
{
public List<string> Product { get; set; }
public List<string> ProductSize { get; set; }
public List<string> PackageType { get; set; }
public List<DateTime> OrderDate { get; set; }
public List<DateTime> DeliveryDate { get; set; }
public List<int> OrderNumber { get; set; }
public List<decimal> Price { get; set; }
public List<int> ItemQuantity { get; set; }
}
}
我正在尝试在我的剃刀视图中的表格中显示此模型。这是该代码:
@using MyModel.MyTools.Orders.SumOrder
@model SumOrder
@{
ViewBag.Title = "View Invoice";
}
<h2>View Invoice</h2>
<table>
@foreach(var prod in Model.OCI)
{
<tr>
<td>
@prod.ClientLocation
</td>
</tr>
foreach (var orderItem in prod.Details)
{
<tr>
<td>
@orderItem.Product
</td>
<td>
@orderItem.ItemQuantity
</td>
</tr>
}
}
</table>
表中的第一行显示正确,这是一个城市的名称,但在下一行我得到了这个:
System.Collections.Generic.List 1[System.String] System.Collections.Generic.List
1[System.Int32]
有人可以向我解释为什么我无法以可读格式返回列表,以及如何解决这个问题?
这是我用来对 ViewInvoice 模型的列表进行分组的代码:
// group the cartItems according to location
List<ViewInvoice> ordersGrouped = cartItems.GroupBy(c => new
{c.ClientLocation})
.OrderBy(c => c.Key.ClientLocation).Select(s =>
new ViewInvoice()
{
ClientLocation = s.Key.ClientLocation,
Details = new List<ViewInvoice.DetailsGroup>()
{
new ViewInvoice.DetailsGroup()
{
Product = s.Select(p => p.Product).ToList(),
ItemQuantity = s.Select(p => p.ItemQuantity).ToList(),
DeliveryDate = s.Select(p => p.DeliveryDate).ToList(),
OrderDate = s.Select(p => p.OrderDate).ToList(),
OrderNumber = s.Select(p => p.OrderNumber).ToList(),
PackageType = s.Select(p => p.PackageType).ToList(),
Price = s.Select(p => p.Price).ToList(),
ProductSize = s.Select(p => p.ProductSize).ToList()
}
}
}).ToList();