title: Passing key-value pair array to Controller action in .NET
body: <p>I have a key-value pair through which I send down values like this:</p>
  
  <pre><code>   $(document).on('click', '.chkAll', function () {
          $("#tableProducts thead tr th input:checkbox").change(function () {
              $(".chkItem").prop('checked', $(this).prop("checked"));
              if ($(this).prop('checked')) {
                  $('tbody tr td input[type="checkbox"]').each(function () {
                      product_ids[$(this).attr('id')] = "Checked";
                      productLocation[$(this).attr('id')] = $(this).attr('location');
                  });
              } else {
                  $('tbody tr td input[type="checkbox"]').each(function () {
                      delete product_ids[$(this).attr('id')];
                      delete productLocation[$(this).attr('id')];
                  });
              }
          });
  </code></pre>
  
  <p>And this is how I post all the keys into the .NET MVC Action:</p>
  
  <pre><code>values: Object.keys(product_ids)
  </code></pre>
  
  <p>And fetching it in Controller:</p>
  
  <pre><code>public ActionResult GetValues(List&lt;string&gt; values)
  {
  // now I have all the keys here but now I'd like values as well...
  }
  </code></pre>
  
  <p>The way I imagine this to be done is by passing down the entire name-value pair array directly into the function and then fetching it, so that then I'd have:</p>
  
  <pre><code>// key (product id) =&gt; 0124914815DD29
  // value =&gt; checked 
  </code></pre>
  
  <p>Both strings ...</p>
  
  <p>I've tried by doing simply like this:</p>
  
  <pre><code>values: product_ids // in jquery post
  </code></pre>
  
  <p>And then fetching the value like this:</p>
  
  <pre><code>public ActionResult GetValues(Dictionary&lt;string,string&gt; values)
  {
  // but now the values dictionary is always empty
  }
  </code></pre>
  
  <p>How can I do this?</p>
  
  <p>Edit: </p>
  
  <p>This is the part where the data is posted:</p>
  
  <pre><code>$(".btnAnalyze").click(function () {
              if (jQuery.isEmptyObject(product_ids) == true) {
                  ShowMessage("You haven't selected any product!");
                  return;
              }
              else {
                  var guid = '@Guid.NewGuid()'
                  var postData = { values: Object.keys(product_ids), drange: $('.range').val(), ID: guid, type: $('input[name=type]:checked').val(), shipping: $('input[name=shipping]:checked').val(), condition: $('input[name=condition]:checked').val(), minprice: $('.txtmin').val(), maxprice: $('.txtmax').val(), Title: $('.txtSearch').val(), negative: $('.txtNegativeKeywords').val(),locations: productLocation };
                  $.ajax({
                      type: "POST",
                      url: "/Analyze/GetAllProducts",
                      data: postData,
                      success: function (data) {
                          if (data == "Error") {
                              alert("Something went wrong");
                          } else if (data=="Ok"){
                              window.location.href = '/Analyze/Index/' + guid // redirect to another page
                          }
                      },
                      dataType: "json",
                      traditional: true
                  });
              }
          });
  </code></pre>
  
  <p>And mapped header of the Action:</p>
  
  <pre><code>  [HttpPost]
          public async Task&lt;JsonResult&gt; GetAllProducts(List&lt;string&gt; values, string drange, string ID, string type, string shipping, string condition, string minprice, string maxprice, string Title,string negative,string minFeedback, string maxFeedback, Dictionary&lt;string,string&gt; locations)
  </code></pre>
  
  <p>@Haim Please see the last parameter that I'm passing into function , that's the one I'm trying to turn into a dictionary...</p>