Reputation: 526
I want to pass array of string to my controller. I pass my data from another c# code.
Here my get request :
String[] varList = new List<String> { "A", "B" }.ToArray();
using (var client = new HttpClient())
{
await client.GetAsync(GetHttpSchema() + HttpContext.Current.Request.Url.Host + "/AController/B?varA=" + varA + "&varB=" + varB + "&varList=" + varList);
}
And here my controller:
public partial class AController : BaseController
{
public async Task B(string A, string B, String[] varList) { }
}
Now in debug i get the following value(Only one value) for varList : System.String[]..... Any suggestions?
Upvotes: 0
Views: 957
Reputation: 32266
First off you can just create an array like this
string[] varList = new [] {"A", "B"}
Second you want to get the values of the array, but the ToString
method for arrays is the default which just gives you the name of the type. Instead you can use string.Join
string listOfValues = string.Join(",", varList);
That will give you a comma separated list of your values. Or you might need to do something like the following to get "&varList=A$varList=B" based on this.
string listOfValues = "$varList=" + string.Join("&varList=", varList);
Personally I don't know what format you need those values in on your http request, so I'll leave that part up to you.
Upvotes: 1