我想用 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>
1 回答
哔哔one
TA贡献1854条经验 获得超8个赞
在您的剃刀页面中,更改为使用以下代码:
<select id="manager" class="form-control form-control-sm" asp-items="@((List<SelectListItem>)IndexModel.ManagementUsers)"> <option value=""></option> </select>
正如@poke 所建议的,您可以直接使用asp-items="@IndexModel.ManagementUsers"
- 1 回答
- 0 关注
- 60 浏览
添加回答
举报
0/150
提交
取消