Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda