如何循环会员列表?

时间:2012-08-09 20:01:28

标签: asp.net-mvc vb.net asp.net-mvc-3 asp.net-membership

我列出了所有会员资格:

Dim allUsers = Membership.GetAllUsers().Cast(Of MembershipUser).ToList

尽管我进行了搜索,但我一直无法弄清楚如何循环执行此操作以执行以下操作。我想循环并检索记录,如果记录包含特定值,则将用户添加到新集合。

for each allusers as user

  ' get user profile
  ' if user profile has a certain value, add it to another collection

end for each

然后,一旦新集合已满,请将该集合输出到我的视图中。

这有意义吗?我怎样才能做到这一点?谢谢。

2 个答案:

答案 0 :(得分:4)

试试这个:

Public Function GetUsers() As IEnumerable(Of MembershipUser)

    Dim newListOfUsers = New List(Of MembershipUser)()
    Dim users As MembershipUserCollection = Membership.GetAllUsers()
    For Each user As MembershipUser In users
        If user.Comment = "A Leather Glove" Then
            newListOfUsers.Add(user)
        End If
    Next

    Return newListOfUsers
End Function

答案 1 :(得分:3)

添加了C#版本:

    var newListOfUsers = new List<MembershipUser>();
    Membership.GetAllUsers().OfType<MembershipUser>().ToList().ForEach( user =>
                                                                                {
                                                                                    if(user.Comment.Equals("A Leather Glove")) newListOfUsers.Add(user);
                                                                                });