我正在尝试查看销售订单中的产品列表。它看起来像这样:
名称OrderDate OrderTotal Products购买<<
被带来的产品。销售订单连接到SalesorderProduct的桥接表。有什么建议。我知道它想要遍历模型,但无法弄明白。
@Html.DisplayFor(model => model.Customer.Name)
@Html.DisplayFor(model => model.OrderDate);
@Html.DisplayFor(model => model.OrderTotal);
@Html.DisplayFor(model => model.SalesOrderProducts);
答案
尝试这样的事情:
@model SalesOrder
@{
ViewBag.Title = "View";
}
View
SalesOrder
@Html.DisplayNameFor(model => model.Name)
@Html.DisplayFor(model => model.Name)
@Html.DisplayNameFor(model => model.OrderDate)
@Html.DisplayFor(model => model.OrderDate)
@Html.DisplayNameFor(model => model.OrderTotal)
@Html.DisplayFor(model => model.OrderTotal)
@foreach (Product p in Model.SalesOrderProducts)
{
@Html.DisplayNameFor(x => x.Name)
@Html.DisplayFor(x => x.Name)
}
@Html.ActionLink("Edit", "Edit", new { id = Model.SalesOrderId }) |
@Html.ActionLink("Back to List", "Index")