如何连接到会员数据库以检索用户帐户列表?例如我有这个连接到我的配置文件: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