I have never encountered an issue like this before (if I had a dollar for every time I said that), so I'll do my best to explain it fully.
For this application I'm building, I'm using CoffeeScript for the client side code, and C# for the server side code.
On the client side I have an array named products. This holds a product name, as well as an id for that product.
I'm simply trying to send this array to the server. Here is what the client is doing:
$http.put("#{$config.serverAddress}UserChoice/GetTotalScoreForProducts?productIDList="
+ _.pluck(products, 'id')
).success (response) ->
console.log "SUCCESS"
console.log response
.error ->
console.log 'error'
Here is the method on the server. Right now I'm just debugging this issue, so there is just a variable there for displaying the length of the array that I'm passing:
[HttpPut]
public void GetTotalScoreForProducts([FromUri] object[] productIDList)
{
int length = productIDList.Length;
}
When debugging, the object[] productIDList only contains one object. However, that one object consists of both of the id's from the array:

So for some reason, the two seperate array objects are being put into one object.
The issue seems to be with how I'm passing the products array to the server, but I can't seem to figure out what I'm doing wrong.
Any help would be greatly appreciated.
Thank you for your time.
EDIT: After trying T.Rahgooy's solution:

EDIT: After hard coding in values to the URL:

EDIT: It's working now! Here's the working code!
$http.put("#{$config.serverAddress}UserChoice/GetTotalScoreForProducts?productIDList="
+ _.pluck(products, 'id').join(&productIDList=)
).success (response) ->
console.log "SUCCESS"
console.log response
.error ->
console.log 'error'

Thanks for helping me out T.Rahgooy =)
You are sending querystring: ? productIDList=x,y, it should be querystring: ? productIDList=x &productIDList=y to receive as an array.
$http.put("#{$config.serverAddress}UserChoice/GetTotalScoreForProducts?"
+ _.map(products, (x)->"productIDList=" + x.id + "&").join(' ')
).success (response) ->
console.log "SUCCESS"
console.log response
.error ->
console.log 'error'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With