1

My ajax method:

$.ajax({
    url: actionURL,
    type: 'POST',
    dataType: 'json',
    data: { values: data },
    success: function (data) {
    }
});

My controller method:

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult SaveParameter(string [][] values)
        {
            ...
        }

I have tried a bunch of things, but nothing is working. How can I compose 'data' in javascript??

2 Answers 2

3

You need to post data in next format

{
"values[0][0]": "Some value",
"values[1][0]": "Some value",
"values[0][1]": "Some value",
"values[1][1]": "Some value",
"values[2][0]": "Some value",
"values[0][2]": "Some value",
"values[2][1]": "Some value",
...
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try with JSON.stringify.

var chiavi = [];
chiavi[0] = ["A", "B"];
chiavi[1] = ["C", "D"];

        $.ajax({
            type: "POST",
            url: jsonUrl, 
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            traditional: true,
            data: JSON.stringify({
                Values: chiavi
            }),
            success: function (result) {
            },
            error: function (response, textStatus, errorThrown) {
            }
        });

1 Comment

@SLC: mmm can you see the request using Chrome Dev Tools or Firebug ? maybe the problem is on MVC side (modelbinding). Be sure to keep the traditional: true in your ajax call or default modelbinding won't work (assuming you're workign with MVC3)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.