我试图加入两个表并使用两个表中的列在强类型列表视图中显示结果,
public ActionResult OrderDetails(int id) {
var query = from o in db.OrderDetails
join a in db.Albums on o.AlbumId equals a.AlbumId
where o.OrderId == id
select new OrderDetail() {
OrderId = o.OrderId,
AlbumId = o.AlbumId,
Quantity = o.Quantity,
UnitPrice = o.UnitPrice,
Album = new Album {
Title = a.Title
}
};
return View(query);
}
这是我的观点
@model IEnumerable<QWERK.OrderDetail>
@{
ViewBag.Title = "OrderDetails";
}
<h2>OrderDetails</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.OrderId)
</th>
<th>
@Html.DisplayNameFor(model => model.AlbumId)
</th>
<th>
@Html.DisplayNameFor(model => model.Quantity)
</th>
<th>
@Html.DisplayNameFor(model => model.UnitPrice)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.OrderId)
</td>
<td>
@Html.DisplayFor(modelItem => item.AlbumId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Quantity)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnitPrice)
</td>
<td>
@Html.DisplayFor(modelItem => item.Album.Title)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.OrderDetailId }) |
@Html.ActionLink("Details", "Details", new { id=item.OrderDetailId }) |
@Html.ActionLink("Delete", "Delete", new { id=item.OrderDetailId })
</td>
</tr>
}
</table>
但我一直收到NotSupportedException
我很确定我得到了错误,因为即时通讯使用OrderDetails模型,但我怎样才能绕过这个来显示来自不同表格的多个列?任何帮助将不胜感激...谢谢