【发布时间】:2020-04-24 21:46:41
【问题描述】:
我有 AccountController.cs 有以下操作:
[HttpGet]
[AllowAnonymous]
public IActionResult Register()
{
ViewBag.Registration = GetRegistration();
return View();
}
ViewBag.Registration包含2个元素,没关系。
然后我得到了Registration.cshtml视图:
@model Registration <!-- this model I'm using for other form -->
@{
Layout = "_Layout";
}
<!-- some code -->
@await Html.PartialAsync("AllRegistered")
和 AllRegistered.cshtml 应显示来自 ViewBag.Registration 的数据:
@model IEnumerable<Registration>
<table>
<tr>
<th>@Html.DisplayNameFor(m => m.Email)</th>
<th>@Html.DisplayNameFor(m => m.City)</th>
</tr>
@if (Model != null && Model.Count() != 0)
{
@foreach (Registration registration in Model)
{
<tr>
<th>@Html.DisplayFor(m => registration.Email)</th>
<th>@Html.DisplayFor(m => registration.City)</th>
</tr>
}
}
</table>
但是没有生成任何东西,我认为模型是空的。
【问题讨论】:
标签: asp.net-mvc asp.net-core model-view-controller razor viewbag