Why is it removed: ASP.NET MVC CheckBoxList (without MVCContrib)

后端 未结 4 944
醉梦人生
醉梦人生 2021-02-02 12:48

Why is the CheckBoxList removed from ASP.NET MVC preview release 5?

Currently I don\'t see any way in which I can create a list of checkboxes (with similar nam

4条回答
  •  星月不相逢
    2021-02-02 13:14

    I recommend using JeremiahClark extension posted above. (CheckBoxList)

    My controller resulted into very simple instructions. For clarify I add a fragment of my code that's absent in the sample.

            var rolesList = new List();
            foreach (var role in Roles.GetAllRoles())
            {
                rolesList.Add(new CheckBoxListInfo(role, role, Roles.IsUserInRole(user.UserName, role)));
            }
            ViewData["roles"] = listaRoles;
    

    And in the view:

    <%= Html.CheckBoxList("roles", ViewData["roles"]) %>

    That's all.

提交回复
热议问题