Reputation: 21430
How do I connect to the membership database to retrieve a list of user accounts? For example I have this to connect to my profiles:
Private db As UserProfileDbContext = New UserProfileDbContext
'
' GET: /UserProfile/
Function Index() As ViewResult
Return View(db.UserProfiles.ToList())
End Function
There doesn't seem to be any user account database context specified in the account model. Should I create one, or is there a better way to retrieve all user accounts into a list like above?
Edit:
I have this code in the controller:
'
' GET: /Account/ViewRegistries
Function ViewRegistries() As ViewResult
Return View(Membership.GetAllUsers().Cast(Of MembershipUser).ToList)
End Function
My view:
@ModelType IEnumerable(Of MyBlog.RegisterModel)
@Code
ViewData("Title") = "Index"
End Code
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
UserId
</th>
<th>
CompanyId
</th>
<th></th>
</tr>
@For Each item In Model
Dim currentItem = item
@<tr>
<td>
@Html.DisplayFor(Function(modelItem) currentItem.UserName)
</td>
<td>
@Html.DisplayFor(Function(modelItem) currentItem.Company)
</td>
</tr>
Next
</table>
But it produces an error:
The model item passed into the dictionary is of type 'System.Collections.Generic.List
1[System.Web.Security.MembershipUser]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[MyBlog.RegisterModel]'.
How can I fix it?
Upvotes: 0
Views: 555
Reputation: 1038710
You could use the membership provider:
Membership.GetAllUsers()
Once you register users this will return the list of all users in the database.
Upvotes: 2