在 View 中创建 SelectList 时,我在预选项目时遇到问题。这是剃刀代码:
@{
ViewBag.Title = "RoleGroupMappings";
}
<h2>Map roles to groups:</h2>
<table>
@foreach (var role in Model.Roles)
{
<tr>
<td>
<p>@role.RoleName: </p>
</td>
<td>
@using (Html.BeginForm("MapGroupsToRole", "Role", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.Hidden("RoleId", role.RoleId)
@Html.DropDownList("Groups", new SelectList(role.Groups, "GroupId", "GroupName", role.Groups.Where(g => g.Mapped).Select(g => g.GroupId)), new { @class = "directory-groups", multiple = "multiple", style = "display: none;" })
<input type="button" value="Clear All" class="btn btn-danger clear-selection" />
<input type="submit" value="Save Changes" class="btn btn-success save-mappings" />
}
</td>
</tr>
}
</table>
有人知道这里有什么问题吗?