title: Return data using JavaScript from view to controller in MVC
body: <p>I have WCF service that should be  consumed by a MVC app. Now I want to delete items from a list using checkbox. When I receive data in my controller, the first WCF method that is called (findAccRoleMapp) should find all data in the table and then call another WCF method (removeAccForRole) to delete that data. </p>
  
  <p>Here is my controller:</p>
  
  <pre><code>    [HttpGet]
      public ActionResult GetAccForRol(string id)
      {
          AccountManagementServiceClient amsc = new AccountManagementServiceClient();
          ViewBag.listAccForRol = amsc.findAllAccByRol(id);
          return View();
  
      }
  
      [HttpPost]
      public ActionResult GetAccForRol(FormCollection collection)
      { 
          AccountManagementServiceClient amsc = new AccountManagementServiceClient();
          AccountManagementViewModel amvm = new AccountManagementViewModel();
  
          foreach(var item in collection)
          {
              if(collection != null)
              {
              string object= item.ToString();
              var accounts = amsc.findAccRoleMapp(object);
              amsc.removeAccFromRole(accounts);
              }
          }
          return RedirectToAction("GetAccForRol");
      }
  </code></pre>
  
  <p>Here is the JS what i have in my view:</p>
  
  <pre><code>    &lt;script type="text/javascript" src="@Url.Content("~/Scripts/")jquery-1.10.2.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  
      var container = []; 
      counter = 0;
  
  $(document).ready(function () {
  
      $('#checkBoxAll').click(function () {
          if ($(this).is(":checked"))
              $('.chkCheckBoxId').prop('checked', true);
          else
              $('.chkCheckBoxId').prop('checked', false);
  
      });
  
      $('#button').click(function () {
  
          console.log("button");
          $('#myTable tr').each(function () {
  
              console.log("table");
  
              $(this).find('td input:checked').each(function () {
  
                  container[counter] = $(this).val();
                  counter++;
              });
  
              console.log("container: " + container);
          });
  
          $.ajax({
              type: "POST",
              url: '/AccountManagement/GetAccForRol',
              data: { 'myArray': container },
              success:
                  alert("fdsfds")
  
          });
  
      });
  
  })
  &lt;/script&gt;
  </code></pre>
  
  <p>I'm trying to mark items from a list through checkbox and send them to my controller. When something is checked it should be saved into an array that i created (container). When the button is clicked I want to pass this array to my controller, but it doesn't work.</p>