Skip to content

The key value to ValueProviderResult GetValue(string key) is "[0]" #4

@iMetro

Description

@iMetro

Tried using this on an [ApiController] Controller method:

[HttpGet]
public IEnumerable<int> Get([FromQuery]IEnumerable<int> id)
{
    return val;
}

When debugging in to GetValue in SeparatedQueryStringValueProvider.cs the key is not "id" as I would expect, instead its "[0]", so the comma separated values entered in the request (query string e.g values?id=100,200,300) will not be found and sent a long to my Get method in ValuesController.

I added a little hack to parse the key value "[0]", converting it to integer (index) and getting the key value ("id") from
_values.Keys.ElementAt(index.Value) which would now get the array values which are split up and returned with
return new ValueProviderResult(splitValues, result.Culture);
Although I send in more than one integer in the query string e.g values?id=100,200,300 only the first value in the integer array remains in the id parameter.

Its tested in a web api core 2.1 project.

Seems like the functionality of the the names of the key parameter coming to GetValue is changed? Based on position instead of name?
Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions