[Vuejs]-Unable to post list of array with axious from vuejs to .net Core

0👍

Can you verify the following codes:

let listOfRights= [
  { RouteName: "Rname", UserName: "Uname" }, 
  { RouteName: "Rname1", UserName: "Uname1" }
]


let url = '/api/UserManager/saveUserRights'

let headers = {
  'Content-Type': 'application/x-www-form-urlencoded'
}

axios.post(url, listOfRights, headers).then((response) => {
  console.log(response)
}, (error) => {
  console.log('EROR:', error)
})

And check the console.logs what it returns.

You can also put a breakpoint on your server side code to see if it does pass the correct data.

0👍

This one worked for me. you can try this

      axios({
    method: 'post',
    url: '/api/customersfilter',
    data: {
      min_number: this.min_number,
      equal_num: this.equal_num,
      max_number: this.max_number,
    }
  })

0👍

Fixed by adding [FromBody] tag in API method
public IActionResult saveUserRights([FromBody]List<SystemMenuRights> listOfRights)
and it is now accepting list as well.

Leave a comment