asp.net-mvc - 我的 ASP.NET MVC 索引表看起来很奇怪 - 列没有显示,其他列在错误的标题下。为什么?
问题描述
我正在用 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>
解决方案
推荐阅读
- python - If-Else 规则对地址的解析进行硬编码
- excel - 使用 VBA 创建发票 - 复制/粘贴循环
- dart - 如何在 Flutter 中围绕图像小部件浮动文本小部件
- css - 复选框十字标记对齐修复
- sapui5 - 在语义页脚的按钮之间添加文本:footerCustomActions
- php - 更改 WP_options 站点 URL 后的 WordPress 后端空白页面
- android - 如何在recyclerView中显示和隐藏imageview
- r - dplyr for SQL 可以在过滤器中将 == NA 转换为 IS NULL 吗?
- c# - 没有参数的分页列表 MVC
- spring - 如何使用没有编码字符的有效 URL 字符串发出请求?