我想用 Active Directory 组中的成员名称填充下拉列表。我目前所能做的就是显示 Microsoft.AspNetCore.Mvc.Rendering.SelectListItem 所以某处出了问题。
这是我到目前为止所拥有的:
public static List<SelectListItem> ManagementUsers = GetManagementUsers();
public static List<SelectListItem> GetManagementUsers()
{
List<SelectListItem> _users = new List<SelectListItem>();
PrincipalContext adServer = new PrincipalContext(ContextType.Domain, "DOMAIN");
GroupPrincipal managerGroup = GroupPrincipal.FindByIdentity(adServer, "Management Group");
if (managerGroup != null)
{
foreach (Principal principal in managerGroup.GetMembers())
{
_users.Add(new SelectListItem { Text = principal.SamAccountName, Value = principal.SamAccountName });
}
}
List<SelectListItem> ManagementUsers = _users;
return ManagementUsers;
}
然后在我的 Razor 页面上:
<select id="manager" class="form-control form-control-sm" asp-items="@(new SelectList(IndexModel.ManagementUsers))">
<option value=""></option>
</select>
哔哔one
相关分类