Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
How to pass a 2d array of numbers to my .Net controller?

I have a 2d javascript array like this

[[2,3],[13,4],[1,19]]

and I want to pass it to my .Net controller

My controller header looks like this

public async Task<ActionResult> UpdateOrder(int[,] order)

My put call looks like this

updateOrder(order: number[][]): Observable<any> {
   return this.http.put(this.baseUrl + 'members/edit/set-order/' + order, {});
}

but I'm getting an error when I hit the controller saying:

'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Int32[,]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\nPath '', line 1, position 2.'

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think you might need to use List<List<int>> type instead of int[,] in c# from default c# JSON serializer

public async Task<ActionResult> UpdateOrder(List<List<int>> order)
about 4 years ago · Juan Pablo Isaza Report

0

You don't need to go through (manual) de/serialization and you don't need a List<List<int>>. I'm able to pass a 2d array of ints with a payload like [[1,2],[3,4],[5,6]] and the below API interface.

public async Task<IActionResult> Test(int [,] ints)

Isn't it your url in the request? You treat the order like a string to cat to the url and the body is empty. And when the body is empty, you see that error you're getting. I think what you need is:

return this.http.put('yourUrl', order, {});

See put. (assuming Angular)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!