【发布时间】:2020-07-01 18:02:42
【问题描述】:
我有 2 个填写的 IList 供应商和 VwSrmAhmSuppliers,它们具有共同的属性 Supplier.SupplierNo 和 VwSrmAhmSupplier.AhmSupplierNo。我想将该公共属性上的它们组合到一个 IList 中,其中各个类属性仍然可以访问,因此我可以在视图中有效地访问它们。
因此,如果我提取 CommonList 中的第一项,然后询问 CommonList(1).Supplier.SupplierNo 和 CommonList(1).VwAhmSrmSupplier.AhmSupplierNo - 这两个字段将是相同的。
也许我有这样的课程:
public class SupplierDetail
{
public Supplier Supplier { get; set; }
public Models.ExternalData.VwSrmAhmSupplier VwSrmAhmSupplier { get;set;}
}
public IList<Supplier> Suppliers { get;set; }
public IList<Models.ExternalData.VwSrmAhmSupplier> VwSrmAhmSuppliers { get; set; }
public IList<SupplierDetail> SupplierDetails;
public async Task OnGetAsync(Boolean? All)
{
//don't show all records unless explicity asked to!
if (All == true)
{
Suppliers = await _context.Supplier
.Include(s => s.Status)
.Include(c => c.Category)
.Include(c => c.Comments)
.OrderByDescending(c => c.CreateDate)
.ToListAsync();
var supplierNos = Suppliers.Select(s => s.SupplierNo).ToList();
VwSrmAhmSuppliers = await _externalcontext.VwSrmAhmSuppliers
.Where(v => supplierNos
.Any(s => s == v.AhmSupplierNo))
.ToListAsync();
SupplierDetails = ??
}
我试图生成的 HTML 表是这样的:
<tbody>
@foreach (var item in Model.CommonList)
{
<tr>
<td>
<a asp-page="./Details" asp-route-id="@item.Id">@Html.DisplayFor(modelItem => item.Supplier.SupplierNo)</a>
</td>
<td>
@Html.DisplayFor(modelItem => item.VwSrmAhmSupplier.AhmSupplierNm)
</td>
<td>
@Html.DisplayFor(modelItem => item.Supplier.CreateDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Supplier.Creator)
</td>
<td>
@Html.DisplayFor(modelItem => item.Supplier.Category.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.Supplier.Status.Description)
</td>
<td>
<a asp-page="./Delete" asp-route-id="@item.Id" class="btn btn-danger">Hide</a>
</td>
</tr>
}
</tbody>
【问题讨论】:
-
问题出在哪里?创建包含这两个字段的类
-
@Selvin 我已将 SupplierDetail 类添加到帖子中并更新了代码。我如何将这些类的列表填充为供应商和 VwSrmAhmSupplier 的复合列表加入 SupplierNo 和 AhmSupplierNo?
标签: c# html linq razor-pages