C# 适用于'类型的构造函数;System.Collections.Generic.IEnumerable`1[TeamCloud.Areas.Identity.Data.TeamCloudUser]';找不到
我正在用IdentityFramework处理我的ASP NET核心项目,现在我需要在RazorPage上的参数表中显示用户列表。此外,我无法想象如何将对象从razor OnGet方法移动到视图(我需要移动成员对象并在视图上显示它)。无论如何,我只需要显示具有与登录用户类似的团队的用户(请参阅下面的代码),但我遇到了这个错误。希望你能帮助我。谢谢 错误 MembersList.cshtmlC# 适用于'类型的构造函数;System.Collections.Generic.IEnumerable`1[TeamCloud.Areas.Identity.Data.TeamCloudUser]';找不到,c#,entity-framework,asp.net-core,entity-framework-core,asp.net-identity,C#,Entity Framework,Asp.net Core,Entity Framework Core,Asp.net Identity,我正在用IdentityFramework处理我的ASP NET核心项目,现在我需要在RazorPage上的参数表中显示用户列表。此外,我无法想象如何将对象从razor OnGet方法移动到视图(我需要移动成员对象并在视图上显示它)。无论如何,我只需要显示具有与登录用户类似的团队的用户(请参阅下面的代码),但我遇到了这个错误。希望你能帮助我。谢谢 错误 MembersList.cshtml @page @using TeamCloud.Areas.Identity.Pages.Team.Man
@page
@using TeamCloud.Areas.Identity.Pages.Team.Manage
@model IEnumerable<TeamCloudUser>
@{
ViewData["Title"] = "Список участников";
ViewData["ActivePage"] = ManageNavPages.MembersList;
}
<br />
<div style="text-align: center;">
<h2 style="font-weight: 700;">Настройки команды</h2>
</div>
<hr />
<partial name="_ManageNav" />
<hr />
<body class="index">
<form method="post" asp-page="MembersList">
<h4 style="font-weight: 700; text-align: center;">@ViewData["Title"]</h4>
<div class="text-center">
<input type="submit" asp-page-handler="AddMember" class="btn alert-primary" value="Добавить участника" style="cursor: pointer; font-weight: 700;" />
<br />
<table class="table" style="text-align: center">
<tr>
<th>
<a>Имя</a>
</th>
<th>
<a>Почта</a>
</th>
<th>
<a>Кол-во файлов</a>
</th>
<th>
<a>Объем памяти</a>
</th>
<th>
<a>Действия</a>
</th>
</tr>
@foreach (var member in Model.TeamCloudUsers)
{
<tr>
<td>
@Html.DisplayFor(modelItem => member.ProfileName)
</td>
<td>
@Html.DisplayFor(modelItem => member.Email)
</td>
<td>
@Html.DisplayFor(modelItem => member.TotalFiles)
</td>
<td>
@Html.DisplayFor(modelItem => member.TotalSize)
</td>
<td>
@if (@member.IsBlockedToUpload == true)
{
<a href="" data-toggle="modal" data-target="#modalOnAllow" class="">
<img style="width: 30px;" src="~/Media/MenuIcons/allow.png" title="Заблокировать" />
</a>
}
else
{
<a href="" data-toggle="modal" data-target="#modalOnBlock" class="">
<img style="width: 30px;" src="~/Media/MenuIcons/block.png" title="Заблокировать" />
</a>
}
<a href="" data-toggle="modal" data-target="#modalOnDelete" class="">
<img style="width: 30px;" src="~/Media/MenuIcons/delete.png" title="Выгнать" />
</a>
<!--modalOnBlock-->
<div class="modal fade" id="modalOnBlock" tabindex="-1" role="dialog" aria-labelledby="title" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="title">Блокировка пользователя</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Запретить участнику "@member.Email" загружать новые файлы в командное хранилище?.
</div>
<div class="modal-footer">
<button type="submit" asp-page-handler="BlockToUpload" class="btn alert-primary" value="@member.Id" name="userId">Запретить</button>
<button type="button" class="btn alert-primary" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>
<!--modalOnAllow-->
<div class="modal fade" id="modalOnAllow" tabindex="-1" role="dialog" aria-labelledby="title" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="title">Разблокировка пользователя</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Предоставить пользователю "@member.Email" доступ к загрузке файлов в хранилище команды?
</div>
<div class="modal-footer">
<button type="submit" asp-page-handler="AllowToUpload" class="btn alert-primary" value="@member.Id" name="userId">Разрешить</button>
<button type="button" class="btn alert-primary" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>
<!--modalOnDelete-->
<div class="modal fade" id="modalOnDelete" tabindex="-1" role="dialog" aria-labelledby="title" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="title">Исключение пользователя</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Исключить пользователя "@member.Email" из команды? (тут подумать над удалением его файлов)
</div>
<div class="modal-footer">
<button type="submit" asp-page-handler="DeleteFromTeam" class="btn alert-primary" value="@member.Id" name="userId">Исключить</button>
<button type="button" class="btn alert-primary" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>
</td>
</tr>
}
</table>
</div>
</form>
}您首先需要学习如何在razor页面中入门: Razor页面不使用
@modelmodelname
,它使用@modelmodel
,这与mvc不同
根据您的要求,您不知道如何在razor页面中返回模型。更改如下:
MembersList.cshtml:
@page
@model MembersListModel //change here
<body class="index">
<form method="post" asp-page="MembersList">
<h4 style="font-weight: 700; text-align: center;">@ViewData["Title"]</h4>
<div class="text-center">
<input type="submit" asp-page-handler="AddMember" class="btn alert-primary" value="Добавить участника" style="cursor: pointer; font-weight: 700;" />
<br />
<table class="table" style="text-align: center">
<tr>
<th>
<a>Имя</a>
</th>
//....
</tr>
@foreach (var member in Model.TeamCloudUsers)
{
<tr>
<td>
@Html.DisplayFor(modelItem => member.ProfileName)
</td>
<td>
@Html.DisplayFor(modelItem => member.Email)
</td>
<td>
@Html.DisplayFor(modelItem => member.TotalFiles)
</td>
<td>
@Html.DisplayFor(modelItem => member.TotalSize)
</td>
<td>
@if (@member.IsBlockedToUpload == true)
{
<a href="" data-toggle="modal" data-target="#modalOnAllow" class="">
<img style="width: 30px;" src="~/Media/MenuIcons/allow.png" title="Заблокировать" />
</a>
}
else
{
<a href="" data-toggle="modal" data-target="#modalOnBlock" class="">
<img style="width: 30px;" src="~/Media/MenuIcons/block.png" title="Заблокировать" />
</a>
}
<a href="" data-toggle="modal" data-target="#modalOnDelete" class="">
<img style="width: 30px;" src="~/Media/MenuIcons/delete.png" title="Выгнать" />
</a>
<!--modalOnBlock-->
<div class="modal fade" id="modalOnBlock" tabindex="-1" role="dialog" aria-labelledby="title" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="title">Блокировка пользователя</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Запретить участнику "@member.Email" загружать новые файлы в командное хранилище?.
</div>
<div class="modal-footer">
<button type="submit" asp-page-handler="BlockToUpload" class="btn alert-primary" value="@member.Id" name="userId">Запретить</button>
<button type="button" class="btn alert-primary" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>
<!--modalOnAllow-->
<div class="modal fade" id="modalOnAllow" tabindex="-1" role="dialog" aria-labelledby="title" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="title">Разблокировка пользователя</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Предоставить пользователю "@member.Email" доступ к загрузке файлов в хранилище команды?
</div>
<div class="modal-footer">
<button type="submit" asp-page-handler="AllowToUpload" class="btn alert-primary" value="@member.Id" name="userId">Разрешить</button>
<button type="button" class="btn alert-primary" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>
<!--modalOnDelete-->
<div class="modal fade" id="modalOnDelete" tabindex="-1" role="dialog" aria-labelledby="title" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="title">Исключение пользователя</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Исключить пользователя "@member.Email" из команды? (тут подумать над удалением его файлов)
</div>
<div class="modal-footer">
<button type="submit" asp-page-handler="DeleteFromTeam" class="btn alert-primary" value="@member.Id" name="userId">Исключить</button>
<button type="button" class="btn alert-primary" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>
</td>
</tr>
}
</table>
</div>
</form>
</body>
@page
@模型成员建模//在此处更改
@ViewData[“标题”]
}
其他的
{
}
Блокировка пользователя
&时代;
电子邮箱:ember.Email?。
Запретить
Отмена
Разблокировка пользователя
&时代;
ППззззазззззззззззззззззззззз107?
Разрешить
Отмена
Исключение пользователя
&时代;
ззззззззззззззззззззз?(тут подумать над удалением его файлов)
Исключить
Отмена
}
MembersList.cshtml.cs:
public class MembersListModel : PageModel
{
//1. add the following property
public IEnumerable<TeamCloudUser> TeamCloudUsers { get; set; }
public void OnGet()
{
//2. set data for the property
//for easy testing,I hard-coded the data
//you could get the data from database
//e.g. TeamCloudUsers = _context.AspNetUserTeams
// .Where(x => x.TeamId == currentTeamId).ToList();
TeamCloudUsers = new List<TeamCloudUser>()
{
new TeamCloudUser(){ ProfileName ="a",IsBlockedToUpload=false,Email="a@qq.com",TotalFiles=2,TotalSize="34"}
};
}
}
public类成员stmodel:PageModel
{
//1.添加以下属性
公共IEnumerable TeamCloudUsers{get;set;}
公共互联网
{
//2.为属性设置数据
//为了便于测试,我对数据进行了硬编码
//您可以从数据库中获取数据
//e、 g.TeamCloudUsers=\u context.AspNetUserTeams
//.Where(x=>x.TeamId==currentTeamId).ToList();
TeamCloudUsers=新列表()
{
new TeamCloudUser(){ProfileName=“a”,IsBlockedToUpload=false,Email=a@qq.com,TotalFiles=2,TotalSize=“34”}
};
}
}
结果:
更新:
将代码修改为:
// change here...
<a href="" data-toggle="modal" data-target="#modalOnBlock_@member.Id" class="">
<img style="width: 30px;" src="~/Media/MenuIcons/block.png" title="Заблокировать" />
</a>
<!--modalOnBlock-->
//change here...
<div class="modal fade" id="modalOnBlock_@member.Id" tabindex="-1" role="dialog" aria-labelledby="title" aria-hidden="true">
//在这里更改。。。
//在这里换车。。。
因此我得到了一个新错误:InvalidOperationException:已经有一个与此连接关联的打开的DataReader,必须先关闭它。在行TeamCloudUsers=_context.Users.Where(x=>x.Id==member.ToList();这是我的OnGet方法:public void OnGet(){var teamFounder=\u userManager.GetUserId(用户);currentUserId=teamFounder;int currentTeamId=FindTeamIdByName();var teamMembers=\u context.AspNetUserTeams.Where(x=>x.TeamId==currentTeamId)。选择(x=>x.UserId);foreach(teamMembers中的var成员){TeamCloudUsers=_context.Users.Where(x=>x.Id==member.ToList();}}我很高兴您解决了这个问题。请注意,我认为您需要更改foreach(teamMembers中的var成员){TeamCl
public class MembersListModel : PageModel
{
//1. add the following property
public IEnumerable<TeamCloudUser> TeamCloudUsers { get; set; }
public void OnGet()
{
//2. set data for the property
//for easy testing,I hard-coded the data
//you could get the data from database
//e.g. TeamCloudUsers = _context.AspNetUserTeams
// .Where(x => x.TeamId == currentTeamId).ToList();
TeamCloudUsers = new List<TeamCloudUser>()
{
new TeamCloudUser(){ ProfileName ="a",IsBlockedToUpload=false,Email="a@qq.com",TotalFiles=2,TotalSize="34"}
};
}
}
// change here...
<a href="" data-toggle="modal" data-target="#modalOnBlock_@member.Id" class="">
<img style="width: 30px;" src="~/Media/MenuIcons/block.png" title="Заблокировать" />
</a>
<!--modalOnBlock-->
//change here...
<div class="modal fade" id="modalOnBlock_@member.Id" tabindex="-1" role="dialog" aria-labelledby="title" aria-hidden="true">