我想发送两个模型
而在其他页面中,可能还需要更多
Controller
ViewBag.Users = db.Users.ToList();
并在视野中
@using Documentation.Models
@{
var Users = (Documentation.Models.User)ViewBag.Users;
}
<table>
@foreach (var item in Users) {
<tr>
<td>
@Html.DisplayFor(item.username)
</td>
</tr>
}
</table>
但是我没有答案,我知道我的代码不正确
我得到这个错误
foreach statement cannot operate on variables of type 'Documentation.Models.User' because 'Documentation.Models.User' does not contain a public definition for 'GetEnumerator'
最佳答案
您应该将viewbag.model转换到“用户列表”。不对用户。
@{
var Users = (List<User>)ViewBag.Users;
}
关于asp.net-mvc - 使用Viewbag传递模型以进行查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19843657/