0

I am new to Axios and have problem in the simple question.

My React code:

const params = {
      "id": "1",
      "name":"Mike"
  };
  axios.request({
      url: 'https://localhost:44343/api/SampleData/test',
      method: 'get',
      data:params
  })

My asp.net core web api:

[HttpGet("test")]
public async Task Test([FromQuery]Model model)

My model:

public class Model
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }

I failed to pass the js object as query string to my api code. model data is null for Id and Name.

2
  • what is the error you are receiving Commented Aug 22, 2019 at 9:54
  • no error,just null for model Commented Aug 22, 2019 at 9:56

1 Answer 1

1

I find the solution:

const querystring = require('querystring');

  const params = {
      "id": "1",
      "name":"Mike"
  };
  axios.request({
      url: 'https://localhost:44343/api/SampleData/test?' + querystring.stringify(params),
      method: 'get',
      data:params
  })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.