0

How do I pass multiple arrays to a controller in jquery without using JSON?

var Test1 = {};
Test1.Source = 'String1';
Test2.Type = 'String2';

var Test2 = {};
Test2.Name = 'String3';
Test2.Location = 'String4';

My controller is

public Int64 Method1(Class1 cl1, Class2 cl2)
{
}

What is the correct syntax for the data property of $.ajax()? With one argument, I can have

data: Test1

However, how does this work with two or more arguments?

0

1 Answer 1

2

Just wrap in another object, like this, so that each array (object actually) is a property:

data: {t1: Test1, t2: Test2 }

You can see an example of this in the docs (although with string values instead).

$.ajax({
  type: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
}).done(function( msg ) {
  alert( "Data Saved: " + msg );
});
Sign up to request clarification or add additional context in comments.

1 Comment

doesn't seem to work for arrays. tried data: { cl1: Test1, cl2: Test2 }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.