Passing an array through a query string

I pass the javascript array through Request.QueryString["cityID"].ToString(), but it shows me the error "invalid arguments":

blObj.addOfficeOnlyDiffrent(Request.QueryString["cityID"].ToString(),
                            Request.QueryString["selectTxtOfficeAr"].ToString());

The method declaration is as follows:

public string addOfficeOnlyDiffrent(string[] cityID, string selectTxtOfficeAr) { }
+5
source share
3 answers

Your method addOfficeOnlyDiffrentexpects a string array argument in cityID, while you pass a single type object stringto your method when called. I believe yours cityIDis a single line, so you can remove the array from the method declaration. In a method call.

Request.QueryString["cityID"].ToString()

the above is a single string, not a string array.

, , , , , ,. , string.Split, , .

EDIT: , :

Request.QueryString["cityID"].ToString() (123456,654311,987654) 

.

string str = Request.QueryString["cityID"].ToString();
string[] array = str.Trim('(',')').Split(',');
blObj.addOfficeOnlyDiffrent(array,
                            Request.QueryString["selectTxtOfficeAr"].ToString());
+5

: "123456,654311,987654"

string[] ids = Request.QueryString["cityID"]
    .Split( new[] {","}, StringSplitOptions.RemoveEmptyEntries );
+1

try it so simple .

 string city = Request.QueryString["cityID"];

 string[] cityID =city.Split(new char[] {','},StringSplitOptions.RemoveEmptyEntries);

You will get a string like "123456.654311.987654" in the city . You get an array in cityID.

0
source

All Articles