如何連接到會員數據庫以檢索用戶帳戶列表?例如我有這個連接到我的配置文件:MVC成員數據庫上下文?
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>
但它會產生一個錯誤:
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]'.
哪有我修復它?
只需創建一個,或去登錄,註冊和註冊在那裏。由於沒有用戶在場,所以一開始你什麼都沒有。 您將不得不創建它。 – Rajesh 2012-08-08 15:43:03
你也可以嘗試在visual studio中使用aspnet配置來創建它。 另外,您可以在Visual Studio命令提示符 – Rajesh 2012-08-08 15:44:14
@Rajesh使用aspnet_regsql.exe的:當我發佈到服務器我還可以使用ASPNET配置?它看起來沒有密碼保護。 – user1477388 2012-08-08 15:45:11