小编Pns*_*ghy的帖子

传递模型以使用viewbag查看

我想在我的视图中发送两个模型,在其他页面中可能需要更多

调节器

ViewBag.Users = db.Users.ToList();
Run Code Online (Sandbox Code Playgroud)

并在视图中

@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>
Run Code Online (Sandbox Code Playgroud)

但我得不到答案,我知道我的代码不对

我收到了这个错误

 foreach statement cannot operate on variables of type 'Documentation.Models.User' because 'Documentation.Models.User' does not contain a public definition for 'GetEnumerator'
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc entity-framework viewbag

6
推荐指数
1
解决办法
2万
查看次数

$ .each不适用于jQuery中的对象数组

我有一个数组,我需要使用每个项目,但是forEach和$ .each在这里不适合数组(jsfiddle

var person = new Array();
person["firstName"] = "John";
person["lastName"] = "Doe";
person["age"] = 46;
jQuery.each(person, function(index, item) {
    alert(index + " : " + item);
});
Run Code Online (Sandbox Code Playgroud)

javascript arrays each jquery

-1
推荐指数
1
解决办法
2910
查看次数