views:

31

answers:

1

Hello,

I have an action on my server side:

public void Action(Container container)
{
}

where container is:

public class Container
{
   public string[] Arr;
}

From the client side, I'm invoking this action in the way below:

$.post("Controller/Action", { Arr: "abc" }, null, "json");

After this, the Arr in container contains one element "abc".

But, while invoking action the way below:

$.post("Controller/Action", { Arr: ["abc", "def"] }, null, "json");

the json array is not deserializing on the server side. The Arr in container is NULL.

How to make this simple thing work ?

Regards

A: 

If you are using jquery 1.4 try this:

$.ajax({
    url: 'Controller/Action',
    type: 'post',
    data: { Arr: [ 'abc', 'def' ] },
    traditional: true,
    dataType: 'json'
});

Notice the traditional flag.

Or if you prefer to continue using $.post():

$.post(
    'Controller/Action', 
    $.param({ Arr: [ 'abc', 'def'] }, true), 
    null, 
    'json'
);
Darin Dimitrov