I've been trying to pass an array of int's created by the following function:
function getCurrentSwimmerList() {
var swimmerList = [];
$("#swimmerTable > tbody > tr").each(function () {
swimmerList.push( parseInt($(this).data('swimmerid')) );
});
return swimmerList;
}
Which I use in token-input to eliminate ceartin suggestions from the search box, so I've set up token-input up like so:
$("#swimmerTokenInput").tokenInput("Admin/retrieveTokensForQuery", {
urlParams: { "IDsAlreadyAdded": getCurrentSwimmerList },
I modified the token-input file to allow you to pass additional paramters in a request by setting urlParams, the addition I made to the code was (in the appropriate section):
//add params passed in as urlParams
if (settings.urlParams != null) {
for (var key in settings.urlParams) {
if (settings.urlParams.hasOwnProperty(key)) {
ajax_params.data[key] = settings.urlParams[key];
}
}
}
I tested and I successfully get these values in the query string (where Ol was typed into the search box):
IDsAlreadyAdded=5%2C6&q=Ol
Which chrome recognizes and parses correctly:
IDsAlreadyAdded:5,6
q:Ol
The signature of the method I'm calling is as follows:
public JsonResult retrieveTokensForQuery(string q, int[] IDsAlreadyAdded)
Each time q successfully get's the appropriate value, however IDsAlreadyAdded always gets a null value. I've looked at various answers on SO (trying traditional=true, or IdsAlreadyAdded[] = ..., having List<int> or IEnumerable<int>) to try fix the problem, but I couldn't get it to work.
Any help would be greatly appreciated.