I'm trying to use Membership.GetAllUsers() to create a list of all of my users in the database. However, I have a model that I use that maps out the user properties (First Name, Last Name, Email, etc.).
How can I add all of the users into List
Receiving an error Cannot implicitly convert type System.Collections.Generic.List
at model.MemberList = tempMemberList;
public ActionResult RenderMembers(ApplicationViewModel model)
{
var memberList = Membership.GetAllUsers();
var tempMemberList = new List<MembershipUser>();
foreach (MembershipUser member in memberList)
{
tempMemberList.Add(member);
}
model.MemberList = tempMemberList;
return PartialView(GetViewPath1("_member-accounts"), model);
}
Model
ublic List<MemberList> MemberList { get; set; }
MemberList class
public class MemberList
{
public Guid Id { get; set; }
public string Username { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string Comment { get; set; }
public bool IsApproved { get; set; }
public bool IsLockedOut { get; set; }
public DateTime LastLoginDate { get; set; }
public DateTime LastLockoutDate { get; set; }
public bool IsFrontendDev { get; set; }
public bool IsBackendDev { get; set; }
}
Your issue is that you are trying to pass a List<MemberUser> into a List<MemberList> which is why you are getting a conversion issue.
You'll have to do direct conversion between your MemberUser class and your MemberList class.
for example (using Linq):
model.MemberList = tempMemberList.Select(m => new MemberList{
Username = m.UserName, //assuming MemberUser class has an UserName property
Email = m.EmailAddress, //assuming MemberUser class has an EmailAddress property,
..... repeat for all properties you are mapping across ...
}).ToList();
Using ASP.Net Membership, get all users
Hi everyone,
I'm trying to use Membership.GetAllUsers() to create a list of all of my users in the database. However, I have a model that I use that maps out the user properties (First Name, Last Name, Email, etc.).
How can I add all of the users into List
Receiving an error Cannot implicitly convert type System.Collections.Generic.List
at model.MemberList = tempMemberList;
{ var memberList = Membership.GetAllUsers();
}
Model
MemberList class
Any pointers much appreciated.
Hi Tom,
Your issue is that you are trying to pass a
List<MemberUser>
into aList<MemberList>
which is why you are getting a conversion issue.You'll have to do direct conversion between your MemberUser class and your MemberList class.
for example (using Linq):
Does that make sense?
Nik
Yep thanks
is working on a reply...