本文介绍了如何在下拉列表中对复选框进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一堆复选框,我想将它放入下拉状态,因为它们占据了整个页面。有没有办法,如果我可以将它们分组到下拉列表。 我不想打扰现有的代码只是想把所有的复选框放到可搜索的下拉菜单,以便我可以搜索和选择我想要的而不是看整页。 (这是我的创建视图代码)I have bunch of check boxes which i want to put into drop down cause they are taking entire page. Is there any way if i can group them into drop down list. I don't want to disturb existing code just want to put all the check boxes in to searchable drop down so that i can search and select whatever i want instead of looking full page.(this my create view code) @ Html.LabelFor(m => m.Workstations,new {@class =control-label}) @for(var i = 0; i< Model.Workstations.Length; i ++) { @Html.LabelFor(m => m.Workstations, new { @class = "control-label" }) @for (var i = 0; i < Model.Workstations.Length; i++) { @ Html.CheckBoxFor(m => Model.Workstations [i] .Selected) @ Html.HiddenFor(m => Model.Workstations [i] .Value) @ Html.DisplayFor(m => Model.Workstations [i] .Text) @Html.CheckBoxFor(m => Model.Workstations[i].Selected) @Html.HiddenFor(m => Model.Workstations[i].Value) @Html.DisplayFor(m => Model.Workstations[i].Text) } } @ Html.ValidationMessageFor(m => m.Workstations,,new {@class =text-danger}) (我在控制器上的代码) for(var i = 0; i< model.Workstations.Length; i ++) { if(model.Workstations [i] .Selected) { var workstation = db.Workstations.Find(model.Workstations [i ] .Value); var documentWorkstation = db.DocumentWorkstations.Create(); documentWorkstation.Document = document; documentWorkstation.Workstation = workstation; foreach(工作站中的var员工.Certificates.Where(m => m.CertificateStatus.Name ==) || m.CertificateStatus.Name ==待定)。选择(m => m.Employee)。其中(m =>!m.Archived)) { documentWorkstation.DocumentWorkstationEmployees.Add(employee); } document.DocumentWorkstations.Add(documentWorkstation ); } } 我有什么尝试过: 我试过bootstrap和jquery。我能够创建下拉但不是我除外。 @Html.ValidationMessageFor(m => m.Workstations, "", new { @class = "text-danger" })(My code on controller) for (var i = 0; i < model.Workstations.Length; i++) { if (model.Workstations[i].Selected) { var workstation = db.Workstations.Find(model.Workstations[i].Value); var documentWorkstation = db.DocumentWorkstations.Create(); documentWorkstation.Document = document; documentWorkstation.Workstation = workstation; foreach (var employee in workstation.Certificates.Where(m => m.CertificateStatus.Name == "Certified" || m.CertificateStatus.Name == "Pending").Select(m => m.Employee).Where(m => !m.Archived)) { documentWorkstation.DocumentWorkstationEmployees.Add(employee); } document.DocumentWorkstations.Add(documentWorkstation); } }What I have tried:I tried bootstrap and jquery. I was able to create drop down but not what I was excepting.推荐答案也许这有帮助吗? 使用jQuery选择多个复选框进行下载 [ ^ ] 正如我所看到的,您可以添加其他元素(如线条)以显示组。 例如Maybe this helps?Dropdown with Multiple checkbox select with jQuery[^]As I can see, you could add other elements like lines to visualize groups.e.g.<li><hr /></li>也许这会有帮助吗? 使用jQuery选择多个复选框的下拉菜单 [ ^ ] 您可以添加线条等其他元素来显示群组。Maybe this helps?Dropdown with Multiple checkbox select with jQuery[^]You could add other elements like lines to visualize groups.<li><hr /></li> 这篇关于如何在下拉列表中对复选框进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 01:59