我有一个带有 EF 的 ASP.NET MVC 4 互联网应用程序。
我的模型:订单和订单详情:
我的观点:
问:如何在我的订单视图中显示我的订单详情记录? (有或没有 JS?;在 webgrid 或表格中?)
创建.cshtml
<div class="editor-label">
@Html.LabelFor(model => model.OrderDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.OrderDate)
@Html.ValidationMessageFor(model => model.OrderDate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.OrderNo)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.OrderNo)
@Html.ValidationMessageFor(model => model.OrderNo)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Total)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Total)
@Html.ValidationMessageFor(model => model.Total)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Shipping)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Shipping)
@Html.ValidationMessageFor(model => model.Shipping)
</div>
@*OrderDetails Part - Works only on the Edit part*@
<table>
<tr>
<th>Product</th>
<th>Unit Price</th>
<th>Quantity</th>
<th>Discount</th>
</tr>
@foreach (OrderDetails item in Model.OrderDetails.OrderBy(d=>d.Products.ProductName))
{
<tr>
<td>@item.Products.ProductName</td>
<td>@item.UnitPrice</td>
<td>@item.Quantity</td>
<td>@item.Discount</td>
<td>
@Html.ActionLink("Edit", "Edit", "OrderDetails", new { id = item.OrderDetailId }, new { }) |
@Html.ActionLink("Details", "Details", "OrderDetails", new { id = item.OrderDetailId }, new { }) |
@Html.ActionLink("Delete", "Delete", "OrderDetails", new { id = item.OrderDetailId }, new { })
</td>
</tr>
}
</table>
<p>
<input type="submit" value="Create" />
</p>