Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda