1

This code returns keys and values from my dict

$.map(dict, function (value, key) {
    console.log(key, value);
});

output:

0 ["19,0,0,0", "23,0,0,0", "21,0,0,0", "22,0,0,0", "20,0,0,0"]
1 ["68,0,0,0", "69,0,0,0", "70,0,0,0", "71,0,0,0", "72,0,0,0", "73,0,0,0", "74,0,0,0", "75,0,0,0"]
2 ["115,0,0,0", "114,0,0,0"]

So, in my opinion it is a Dictionary <string,string[]>

I want to pass the dict to controller

$.ajax({
   url: '/Home/SomeAction',
   type: 'GET',
   data: { categoryId: categoryId, traitValues: dict }
});

public ActionResult SomeAction(int categoryId, Dictionary<string,string[]> traitValues){...}

And here is a problem. In controller key dictionary is ok (0,1,2). But value is empty.

So how I can pass my dict from js to controller?

thenewgai
  • 55
  • 6
  • 1
    If the key is always the ordinal number depicting the value's position in the "dict" which increases by one by every value, can't your object then just be mapped to a `List`? – cbr Mar 15 '15 at 15:35
  • it's a helpful idea and works – thenewgai Mar 15 '15 at 15:47
  • In order to bind to a dictionary your json needs to be in the format shown in [this answer](http://stackoverflow.com/questions/28297075/transmit-javascript-object-into-controller-action-as-dictionary/28298048#28298048) –  Mar 15 '15 at 22:25
  • Please check this answer to see if it helps https://stackoverflow.com/questions/40026670/javascript-array-to-mvc-controller – SheldonZ May 31 '19 at 16:05

0 Answers0