I'm using the GetPathByAction method of the ASP.NET 5 LinkGenerator class to create links for my controller actions. This works well in general, but I just ran into a case where it creates bad query parameters. In this case I pass in the query parameters and use the current controller and action:
GetPathByAction(httpContextAccessor.HttpContext, null, null, values);
values here is an object that has a few members, the problematic one being the MyDict member which is a Dictionary<string,string> with one key "foo" with the value "bar".
The query string when I call this endpoint is something like the following:
/myEndpoint?page=1&myDict[foo]=bar
This is properly handled by the model binding and I get my object with the myDict dictionary and the proper values. When I now try to modify the page parameter and generate a new URL with GetPathByAction I get the following output from it:
/myEndpoint?page=2&myDict=[foo, bar]
The output is URL-encoded, I decoded it here to make this easier to read. To me this output seems to be simply wrong, it treats the dictionary as if it were an array (and even then this is not the way arrays are treated in model binding).
My expectation here was that the ASP.NET Url-generating functions would work the same way as the model binding. If ASP.NET can understand the parameter from a URL, it should be able to generate a valid URL from that parameter again.
Am I doing something wrong here or is this a bug? Are there any other ways to generate URLs for a controller action with specific parameters that can handle Dictionary parameters?