侧面下拉框中的复选框

时间:2019-02-18 15:11:43

标签: .net asp.net-mvc-4

我有一个带有许多复选框的mvc代码,它们已连接到数据库。由于这些复选框正在增长,所以我的经理要求我将所有复选框放到下拉菜单中,以使这些复选框在网页上不会占据太多位置。

控制器上的代码

    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);
  }

 }

Code on View

  <div class="col-md-4">
  <div class="form-group">
   @Html.LabelFor(m => m.Workstations, new { @class = "control-label" })

 @for (var i = 0; i < Model.Workstations.Length; i++)
 {
 <div class="checkbox">
<label>
 @Html.CheckBoxFor(m => Model.Workstations[i].Selected)
 @Html.HiddenFor(m => Model.Workstations[i].Value)
 @Html.DisplayFor(m => Model.Workstations[i].Text)
  </label>
</div>
 }
</div>

如何解决此问题,有什么办法可以将此代码放入下拉部分?

0 个答案:

没有答案