EF を使用した ASP.NET MVC 4 インターネット アプリケーションがあります。
私のモデル: Orders と OrderDetails:
私の見解:
Q: 注文ビューに自分の orderdetails レコードを表示するにはどうすればよいですか? (JS の有無にかかわらず?; Web グリッドまたはテーブルで?)
作成.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>