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

200
Views
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 answers
Answer question

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 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!