title: MVC 3: how to update checkboxlist when dropdownlistitem is selected?
body: <p>for last two days i was trying to figure out how to update a checkboxlist dynamicly when a new item in dropdownlist is selected by help of javascript. </p>
  
  <p>Ive done same thing for a week ago where i should do update to a from a dropdownlist to a dropdownlist. </p>
  
  <p>What ive got so far : </p>
  
  <p><strong>View</strong></p>
  
  <pre><code>@using (Html.BeginForm())
  {
      @Html.DropDownListFor(x =&gt; x.User, (IEnumerable&lt;SelectListItem&gt;)Model.UserList, "-- vælg bruger --")
      if (Model.checkboxlist != null)
      {
         for (var i = 0; i &lt; Model.checkboxlist.Count; i++)
         {
          &lt;div class="editor-label"&gt;
             @Html.CheckBoxFor(c =&gt; Model.checkboxlist[i].check)
              @Html.LabelFor(c =&gt; Model.checkboxlist[i].Id, Model.checkboxlist[i].Id)
              @Html.HiddenFor(c =&gt; Model.checkboxlist[i].Id)
  
          &lt;/div&gt;
         }
      }
  }
  &lt;script type="text/javascript"&gt;
      $('#User').change(function () {
      alert('HEJ!');
          var selectedUser = $(this).val();
          alert(selectedUser);
          if (selectedUser != null &amp;&amp; selectedUser != '-- vælg bruger --' &amp;&amp; selectedUser != '') {
              $.getJSON('@Url.Action("getPdfCheckBoxList","Admin")', { username: selectedUser },
              function (employee) {
  
                  var checkboxlist = $('#checkboxlist');
                  checkboxlist.empty();
  
                  $.each(employee, function (index, employee) {
                      checkboxlist.append($('&lt;checkbox/&gt;', {
                          checked = 'false'
                      }));
                  });
              });
  
          }
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>when i am loading view Model.checkboxlist is null cause i dont return anything to model apart of dropdownlist items.</p>
  
  <p>ControllerAction : </p>
  
  <pre><code>public ActionResult getPdfCheckBoxList(String username)
  {
      MethodService service = new MethodService();
      var list = new List&lt;PDFCheckBoxList&gt;();
  
  
      foreach (var pdfCheckBoxList in getPDFFileNames(username))
      {
          list.Add(new PDFCheckBoxList { check = false, Id = pdfCheckBoxList });
      }
      return Json(list, JsonRequestBehavior.AllowGet);
  } 
  </code></pre>
  
  <p>Right now even Alert("HEJ") doesnt even get fired, and i simply cant figure out why... Help please? </p>