Reeggiie Reeggiie - 11 months ago 53
Javascript Question

Ajax not passing array to Controller Action?

Iv searched related questions, but still not able to get this to work in my situation. I am working in ASP.NET MVC.

I have a report that has 3 filters. Only 1 value can be selected for Filters 1 and 2. My 3rd filter is a Multi Select filter. I load an array with all the values selected from the Multi Select Filter, then I want to pass all 3 Filters to my controller action. Filters 1 and 2 work correctly, but my Multi Select Filter is not being passed, and shows as Null in my Actions parameter.

Below is my JavaScript and Ajax call

$('#applyFilter').click(function () {

var options = new Array();
//Fill array with values from Multi Select Filter
$('#treeFilter > option:selected').each(
function (i) {
options[i] = $(this).text();

var filter1 = $('#LOCFilterDropdown').val();
var filter2 = $('#ESNFilterDropdown').val();

type: "GET",
url: "/Home/FilterReport",

data: {
filterOne: filter1,
filterTwo: filter2,
multiselectFilter: options
success: function (result) {

The receiving Action

public ActionResult FilterReport(string filterOne,string filterTwo, int? page, List<string> multiselectFilter)
//filterOne contains correct value
//filterTwo contsins correct value
//multiSelectFilter contains null

//returns partial view


Can anyone tell me why my

List<string> multiselectFilter
//Iv also tried string[] multiselectFilter, but this didnt change anything

is now receiving the array from the ajax call?


You are trying to send a complex object with GET method. The reason this is failing is that GET method can't have a body and all the values are being encoded into the URL.

Similar Question

Complex type is getting null in a ApiController parameter

I Would just join the Multiselectfilter in client and split them in server side

 multiselectFilter: options.join(',')

    public ActionResult FilterReport(string filterOne, string filterTwo, int? page, string multiselectFilter)
        string[] array = multiselectFilter.Split(',');

        //returns partial view