【问题标题】:Display category description (one time) in a list of product in asp.net mvc在asp.net mvc的产品列表中显示类别描述(一次)
【发布时间】:2019-05-03 08:57:10
【问题描述】:

我在一次销售的模型中有一个列表,并且我在其中显示了所有产品,但是,现在我需要显示类别描述,(一次)来自seme类别的每个产品,怎么办?

Product          Quantity          Price

*Licors (This is the category)
Brugal           1                 500
Barcelo          15                700

*Fruits (This is the category)
Apple            1                 25
Banana           3                 5

我需要显示的是(向上)产品名称上的描述 @Html.DisplayFor(modelItem => item.Product.Category.Description) 这是我的代码

<table>
  <thead>
    <tr>
      <th class="center"></th>
      <th>Serv./Prod.</th>
      <th class="center">Cant.</th>
      <th class="right">Precio</th>
    </tr>
  </thead>
  <tbody>                  
 @foreach (var item in Model.SalesDetails.OrderBy(p=>p.Product.CategoryId))
  {
    <tr>
      <td class="center"></td>
      <td class="left">   @Html.DisplayFor(modelItem => item.Product.Name)</td>
      <td class="right">     @Html.DisplayFor(modelItem => item.Quantity)</td>
      <td class="center">   @Html.DisplayFor(modelItem => item.Product.SellPrice)</td>
    </tr>
}
  </tbody>
</table>

【问题讨论】:

  • 描述在哪里?
  • 在foreach里面吗?
  • @TAHASULTANTEMURI 为什么你的名字对我大喊大叫?
  • @FrankerZ 对不起,先生,我无法理解您的意思
  • Product.CategoryId 有一个 Product.Category.Description

标签: c# asp.net asp.net-mvc web


【解决方案1】:

这是我的例子。如果您想了解更多详情,请告诉我。

@{    
list = list.OrderBy(p => p.id).ToList();
}

<table>
@foreach (var item in list)
{
    <tr>
        <td class="center"></td>
        <td class="left">   @Html.DisplayFor(modelItem => item.product)</td>
        <td class="right">     @Html.DisplayFor(modelItem => item.quantity)</td>
        <td class="center">   @Html.DisplayFor(modelItem => item.id)</td>
    </tr>
}
</table>

【讨论】:

  • 感谢您的示例,但在这种情况下,它不起作用,因为您的示例与我在 Model.SalesDetails.OrderBy(p=>p.Product.类别ID)
  • 它适用于我的电脑。你可能还有其他一些错误。如果您需要帮助,请提供更多详细信息;)
  • Emmm,让我更明确地说,它有效,但是,与我在我的帖子中的相同,所以,它有效,但不要做我需要的事
猜你喜欢
  • 1970-01-01
  • 2021-10-09
  • 2019-01-20
  • 2022-09-23
  • 1970-01-01
  • 2021-06-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多