我需要按角色过滤用户,但所有用户都属于两个角色
示例:对于一个用户,对于Admin
另一个用户。Group1
User
Group1
现在我想按Group1
Role 过滤它们并忽略Admin
and User
。
public ViewResult Index()
{
string[] roles = Roles.GetRolesForUser();
var group = string.Join(" ", roles );
group = group.Replace("Admin", "");//Used this to single out Group1 from Admin user
return View(new UserViewModel
{
Users = _userService.FindAll().Where(x => Roles.GetRolesForUser(x.UserName).Contains(group)),
Roles = roles
});
}
这不会出错,但它显示为空。我想我知道为什么,但仍然无法弄清楚如何绕过它......