Redirect to action with querystring array

Viewed 133

I'm trying to do a redirect to action with a querystring array:

string[] variantIds = new { 
  "test1",
  "test2",
};

return RedirectToAction("SamplesOrderStep3", new { variantIds });

But this redirects to

sample-order-step3?variantIds=System.String%5B%5D

How do I get it to go to

sample-order-step3?variantIds=test1&variantIds=test2
3 Answers

Looks like you are unable to redirect directly using redirect to action - in the end I used a mixture or Url.Action and Redirect:

return Redirect($"{Url.Action("SamplesOrderStep3")}?variantIds={string.Join("&variantIds=", variantIds)}");

I believe that it's better if you convert it to string with a separator

string variantIdsString = "test1,test2";

Or try to use a list of strings instead of an array.

Related