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

202
Vistas
params return null in axios post method

I have a simple code as below, but the productArray in axios always returns null.

It works when I do it with jquery. what am i missing?

$.post(`/api/${productId}/getProducts`, { products: productArray })
My Controller
[HttpPost]
public async Task<IActionResult> GetProducts(int productId, Request request)
My class
public class Request 
{
public List<ProductDetails> Products { get; set; }
}

public class ProductDetails
{
public int ProductId { get; set; }
public int Price { get; set; }
}
axios
async function GetAllProducts() {
    let productArray = [];
    productArray.push({ productId: "1",  price: "5" });
    const response = await axios.post(`/api/${productId}/getProducts`, productArray)
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The "thing" you are sending with jQuery is an object that contains a single key/value pair of products: productArray but what you are sending in axios is only the productArray, not the object containing the array. if you create the object and send that, your axios call would match your jQuery call

async function GetAllProducts() {
    let productArray = [];
    productArray.push({ productId: "1",  price: "5" });
    let o = { products: productArray };
    const response = await axios.post(`/api/${productId}/getProducts`, o)
}

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