当用于在details.cshtml页面上查看时,我用什么代码来查看模型中的项目列表?

问题描述 投票:0回答:1

我正在尝试查看销售订单中的产品列表。它看起来像这样:

名称OrderDate OrderTotal Products购买<<<试图让它列出

被带来的产品。销售订单连接到SalesorderProduct的桥接表。有什么建议。我知道它想要遍历模型,但无法弄明白。

      <th>
          @Html.DisplayFor(model => model.Customer.Name)
      </th>

      <th>
          @Html.DisplayFor(model => model.OrderDate);
      </th>

      <th>
          @Html.DisplayFor(model => model.OrderTotal);
      </th>

      <th>
          @Html.DisplayFor(model => model.SalesOrderProducts);
      </th>



      <th></th>
  </tr>
c# asp.net razor
1个回答
0
投票

尝试这样的事情:

@model SalesOrder

@{
    ViewBag.Title = "View";
}

<h2>View</h2>

<div>
    <h4>SalesOrder</h4>
    <hr />
    <dl class="dl-horizontal">
        <dt>
            @Html.DisplayNameFor(model => model.Name)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Name)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.OrderDate)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.OrderDate)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.OrderTotal)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.OrderTotal)
        </dd>
    </dl>

        @foreach (Product p in Model.SalesOrderProducts)
        {
            @Html.DisplayNameFor(x => x.Name)

            @Html.DisplayFor(x => x.Name)
            <br/>
        }


</div>
<p>
    @Html.ActionLink("Edit", "Edit", new { id = Model.SalesOrderId }) |
    @Html.ActionLink("Back to List", "Index")
</p>
© www.soinside.com 2019 - 2024. All rights reserved.