2

I'm following the answer provided by Mrchief in this question:

How to pass an array of integers to a asp.net web api rest service

The problem I'm experiencing is that the AttemptedValue contains the key of the array (see screenshot below).

screenshot: visual studio

The code that converts this string into an array expects the AttemptedValue string to be like this:

"123, 435, 234"

So what's going on here?


Edit

The url:

https://localhost:44301/api/sickleaves/sick/multiple/employeeIds=123,435,234

The endpoint signature:

[Route("api/sickleaves/sick/multiple/{employeeIds}")]
public async Task<IHttpActionResult> PostSick([ModelBinder(typeof(CommaDelimitedArrayModelBinder))] int[] employeeIds)
Community
  • 1
  • 1
transporter_room_3
  • 2,583
  • 4
  • 33
  • 51

1 Answers1

2

You have entirely different situation from what you have linked. In the link they use query string parameters:

/Categories?categoryids=1,2,3,4

Here key is categoryids and value is 1,2,3,4.

What you are using is route parameter:

multiple/{employeeIds}
multiple/employeeIds=123,435,234

So here key is whatever is declared in a {} placeholder in route, employeeIds in this case, and value is what is being passed instead of the placeholder in actual url, employeeIds=123,435,234.

To make you custom binder relevant, you need to:

  1. Either switch to query string: multiple?employeeIds=123,435,234
  2. Or change the URL: multiple/123,435,234 (not sure it will work though, but feel free to give it a try)
Andrei
  • 55,890
  • 9
  • 87
  • 108