我正在用 ASP.NET MVC 和 EF 构建我的第一个项目。到目前为止,其他一切都运行良好,但我对下表的结果感到困惑。第一列 (Item) 是正确的,但是 Product 没有显示出来(它已填充,我检查了),并且 CRUD 列应该显示这三个按钮,而不是出现在表格的右侧。我忽略了这可能是一件非常非常愚蠢的事情,但我看不到是什么。
这是我的索引视图中的代码。如果您需要我发布其他文章告诉我什么,我不想在这里发布各种不必要的代码以使其过于复杂。这
"@Html.Partial("_TableButtonsPartial",
new SmallButtonModel
{ ItemID = item.ItemID, ProductID = item.ProductID }"
是这三个按钮的代码。它们发挥应有的作用,只是被抵消了。
@model IEnumerable<Memberships.Areas.Admin.Models.ProductItemModel>
@using Memberships.Extensions
@using Memberships.Areas.Admin.Models;
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.Partial("_CreateButtonPartial")
</p>
<table class="table table-condensed table-striped">
<tr class="success">
<th>@Html.DisplayNameFor(model => model.ItemTitle)</th>
<th>@Html.DisplayNameFor(model => model.ProductTitle)</th>
<th>CRUD</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td> @Html.DisplayFor(modelItem => item.ItemTitle)</td>
<td> @Html.DisplayFor(modelItem => item.ProductTitle) </td>
<td>
@Html.Partial("_TableButtonsPartial",
new SmallButtonModel
{ ItemID = item.ItemID, ProductID = item.ProductID })
</td>
</tr>
}
</table>
enter code here
编辑:从 _TableButtonsPartial 部分视图添加代码。
@model Memberships.Areas.Admin.Models.SmallButtonModel
@using Memberships.Areas.Admin.Models;
@*Now it's time to build the tiny buttons from SmallButtonModel into a row that can be displayed on an index page.*@
<td style="width:120px;">
<div class="btn-group" role="group">
@Html.Partial("_SmallButtonPartial",
new SmallButtonModel
{
Action = "Edit",
ButtonType = "btn-primary",
Glyph = "pencil",
Text = "Edit Button",
ID = Model.ID,
ItemID = Model.ItemID,
ProductID = Model.ProductID,
SubscriptionID = Model.SubscriptionID
})
@Html.Partial("_SmallButtonPartial",
new SmallButtonModel
{
Action = "Details",
ButtonType = "btn-success",
Glyph = "list",
Text = "Detail Button",
ID = Model.ID,
ItemID = Model.ItemID,
ProductID = Model.ProductID,
SubscriptionID = Model.SubscriptionID
})
@Html.Partial("_SmallButtonPartial",
new SmallButtonModel
{
Action = "Delete",
ButtonType = "btn-danger",
Glyph = "trash",
Text = "Delete Button",
ID = Model.ID,
ItemID = Model.ItemID,
ProductID = Model.ProductID,
SubscriptionID = Model.SubscriptionID
})
</div>
</td>