我将使用asp.net MVC4进行web应用程序开发。
我想要遍历来自ViewModel的对象列表。
以下是该对象的类:
public class User
{
public int Id {get; set;}
public string Name {get; set;}
public string Address {get; set;}
public string Department {get; set;}
}
以下是我的ViewModel类:
public class UserViewModel
{
public List<User> AllUsers {get; set;}
public bool IsDeleted {get; set;}
}
正如在
UserViewModel
类中所见,我有一个User
类型对象列表。AllUsers
列表中的每个用户对象都需要使用Jquery
迭代并从中获取数据。为此,我尝试执行以下操作:$(@Model.AllUsers).each( function(){ .... });
我尝试使用上述方法进行不同的组合,但是没有成功。有人能为此提出解决方案吗?
提前感谢您的帮助。
$.each()
函数:$.each(@Model.AllUsers, function() {});
? - SzybkiSasza$.each
或者@foreach
,它们都是做同样的事情。如果你想要访问外部变量,你可以通过@
符号来轻松访问它们,比如在循环中使用@if(@status == false)
。 - super cool@{bool status = true}
? - super cool