I need to post dictionary to server. My code works fine.
Server-side:
[HttpPost]
public JsonResult SomeMethod(Dictionary<string, string> someData) {
SomeAction();
return null;
}
Client-side:
postMethod = function() {
var someData = {};
someData["1"] = "1";
someData["2"] = "2";
$.ajax({
url: '/SomeMethod/',
type: 'POST',
traditional: true,
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
someData: someData
}),
});
return false;
};
But if i change type of someData
in controllers method to Dictionary<int, int>
and try to pass
someData[1] = 1;
someData[2] = 2;
someData
in controllers method is empty.
Why? And what difference between passing dictionary of string and dictionary of integer?