我的索引视图中显示了三种产品,分为3个插槽
<div class="panel panel-body">
<div class="col-md-4 table-responsive" id="carTable"></div>
<div class="col-md-4 table-responsive" id="boatTable"></div>
<div class="col-md-4 table-responsive" id="otherProductsTable"></div>
</div>
并且工作得很好。像Ny,迪拜这样的部门很有活力,这是我的班级:
public class Departments
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int DeptId { get; set; }
public string DeptName { get; set; }
}
但现在我正在尝试展示我的产品摘要,包括他们所属的部门,如下面的截图所示:
通过这样的编码:
public async Task<ActionResult> GetProductSummary()
{
using (context)
{
return (PartialView("_ProductSummary", await context.Inventories.Include(b =>b.KindOfProducts).GroupBy(m => m.KindOfProducts.ProductType).Select(g => new InventoryModel { BetName = g.Key, Status = g.Sum(c => c.Status) }).ToListAsync()));
}
}
我得到的结果如下所示:
但我真正想要的是这样的:
我不知道如何更改我的Linq查询,在此之前如何创建一个良好的结构化ViewModel。现在我有这个不完整的ViewModel:
public class InventoryModel
{
// I don't know if I need all this properties...
public KindOfProducts ProductType { get; set; }
public string ProductType { get; set; }
public int KindOfProductId { get; set; }
public Department department { get; set; }
public string DeptName { get; set; }
public int DeptId { get; set; }
public int Status { get; set; }
}
提前谢谢!