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

146
Vistas
Sending array from URL.Action and getting null in controller

I have a function that after adding items in a for loop calls the controller through the action URL sending the arr parameter (array), I see that it sends the data but null appears in the controller parameter. I wanted to know what could be wrong?

Javscript Function

function Submit() {
  QRCodeval.forEach((code) => arr.push(code.innerHTML));
  window.location.href = "@Url.Action("ReceivedFromBarCode","PurchaseOrder")?" +arr;
}

Link generated by the controller:

http://localhost:56978/PurchaseOrder/ReceivedFromBarCode?JJJKP,RRPRQ,PPLQR

Controller where I get null in the arr parameter.

public async Task<ActionResult> ReceivedFromBarCode(string[] arr)
{
    return View();
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The MVC model binder expects arrays to be passed in the following format: arr=value1&arr=value2&...

You can use map() and join() to create the correct format. But you'll also need to encode the values since they are parameters in a URL. encodeURIComponent can help with that:

let urlParams = array.map((val) => { 
                         return `arr=${encodeURIComponent(val)}` 
                     }).join('&');

window.location.href = "@Url.Action("ReceivedFromBarCode","PurchaseOrder")?" 
                         + urlParams;

And append the urlParams to your URL. Example output in snippet below:

let array = ["value1", "http://example.com?x=1", "<script>alert('')</sctipt>"];

let urlParams = array.map((val) => { 
                       return `arr=${encodeURIComponent(val)}` 
                     }).join('&');

console.log(urlParams);

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