Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload