メンバーシップ データベースに接続してユーザー アカウントのリストを取得するにはどうすればよいですか? たとえば、私は自分のプロファイルに接続するためにこれを持っています:
Private db As UserProfileDbContext = New UserProfileDbContext
'
' GET: /UserProfile/
Function Index() As ViewResult
Return View(db.UserProfiles.ToList())
End Function
アカウント モデルで指定されたユーザー アカウント データベース コンテキストがないようです。作成する必要がありますか、または上記のようなリストにすべてのユーザー アカウントを取得するためのより良い方法はありますか?
編集:
コントローラーに次のコードがあります。
'
' GET: /Account/ViewRegistries
Function ViewRegistries() As ViewResult
Return View(Membership.GetAllUsers().Cast(Of MembershipUser).ToList)
End Function
私の見解:
@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>
しかし、それはエラーを生成します:
ディクショナリに渡されるモデル アイテムのタイプは「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]」です。
どうすれば修正できますか?