【发布时间】:2020-10-24 18:10:35
【问题描述】:
我正在尝试在我的视图中使用模型中的值构建一个表。我在 foreach 循环中的模型为空。我的控制器中是否缺少某些东西?
我的视图 (cshtml)
@model IEnumerable<MyApp.Models.BookModel>
@{
ViewData["Title"] = "Index";
}
<table>
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.bookName)
</th>
<th>
@Html.DisplayNameFor(model => model.Author)
</th>
</tr>
</thead>
<tbody>
@foreach(var b in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => b.bookName)
</td>
<td>
@Html.DisplayFor(modelItem => b.Author)
</td>
</tr>
}
</tbody>
</table>
谢谢!
【问题讨论】:
-
您能否提供有关控制器中操作的更多详细信息?
标签: asp.net-core model-view-controller razor foreach null