0

Is it possible to pass a jagged array to a web API method? For example:

public IEnumerable<Object> Get([FromUri]int[][] jaggedArray)

How would I be able to to pass a value for jaggedArray in my web request? The parameter doesn't necessarily have to be [FromUri]

6
  • Is there a reason you can't pass a single array and additionally what the dimensions should be? That way the server could just reconstruct it Commented Jan 29, 2014 at 22:00
  • @JaredPar Passing an array of objects each with an int[] attribute would be possible. I just want to see if the more convenient solution of a multidimensional array is possible. Commented Jan 29, 2014 at 22:06
  • If the framework doesn't support it, you could always create a custom databinder. Commented Jan 29, 2014 at 22:13
  • It is more like jagged array Commented Jan 29, 2014 at 22:20
  • Does traditional forms-style list model-binding not work? E. g. can you pass "[0][0]=1,[0][1]=2,..."? Commented Jan 30, 2014 at 0:08

1 Answer 1

1

I managed to figure it out. The parameter can be passed using the following format:

http://www.example.com/api/endPoint?jaggedArray[0][]=406&jaggedArray[0][]=404&jaggedArray[1][]=405&jaggedArray[1][]=407

This causes a jagged array containing two arrays, each with two numbers (406 and 404 for the first, then 405 and 407 for the second,) to be received.

Sign up to request clarification or add additional context in comments.

Comments

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.