Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing array via query string

Tags:

c#

asp.net

I am passing a javascript array via Request.QueryString["cityID"].ToString(), but it shows me an error of "invalid arguments":

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

The method declaration looks like:

public string addOfficeOnlyDiffrent(string[] cityID, string selectTxtOfficeAr) { }
like image 564
SHAKEEL HUSSAIN Avatar asked Jan 30 '13 04:01

SHAKEEL HUSSAIN


People also ask

Can we pass array in query string C#?

You can pass data, including arrays via the Query String when using NavigationManager to navigate to a different page in your Blazor app.

How do you query an array?

To query if the array field contains at least one element with the specified value, use the filter { <field>: <value> } where <value> is the element value. To specify conditions on the elements in the array field, use query operators in the query filter document: { <array field>: { <operator1>: <value1>, ... } }


1 Answers

Your method addOfficeOnlyDiffrent is expecting a string array arguement in cityID whereas you are passing a single string type object to your method in call. I believe your cityID is a single string so you can remove the array from the method declaration. In your method call.

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

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

If your query string contains a string array, then values are probably in string representation, separated by some character, for example ,. To pass that string to the method, you can call string.Split to split the string to get an array.

EDIT: From your comment, that your query string contains:

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

You can do the following.

string str = Request.QueryString["cityID"].ToString();
string[] array = str.Trim('(',')').Split(',');
blObj.addOfficeOnlyDiffrent(array,
                            Request.QueryString["selectTxtOfficeAr"].ToString());
like image 188
Habib Avatar answered Oct 04 '22 15:10

Habib