vs'12 asp.net C# MVC4 EF代码先
在控制器中
var usernames = Roles.GetUsersInRole("Admin");
var adminUsers = db.UserProfiles
.Where(x => !usernames.Contains(x.UserName)).ToList();
List<UserProfiles> myList = adminUsers.ToList();
IEnumerable<UserProfiles> myEnumerable = myList;
ViewBag.DDLRoles = myEnumerable;
进入视图状态的错误
The ViewData item that has the key 'DDLRoles' is of type 'System.Collections.Generic.List'1[[OG.Models.UserProfiles, OG, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' but must be of type 'IEnumerable<SelectListItem>'.
而且我一直在尝试将此查询转换为IEnumerable<SelectListItem>
疯狂,如果有人可以帮助我以正确的方式进行转换,我将不胜感激。
另外,如果我没有说清楚,我正在做的是从 linq 查询中获取不属于“管理员”角色的用户列表,并且我试图在 DropDrownList 中显示它们
编辑:视图
@model OG.Models.UserProfiles
然后稍后
@Html.DropDownList("DDLRoles", (SelectList)ViewData["SelectedValue"])