8

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) { }
3
  • how your query string looks like? Commented Jan 30, 2013 at 4:47
  • 1
    You may find your answer in this thread.. stackoverflow.com/questions/6243051/… Commented Jan 30, 2013 at 4:49
  • Request.QueryString["cityID"].ToString() (123456,654311,987654) Commented Jan 30, 2013 at 4:49

3 Answers 3

7

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());
Sign up to request clarification or add additional context in comments.

3 Comments

Request.QueryString["cityID"].ToString() havaing multiple iD whic i need to pass addOfficeOnlyDiffrent metod HOW CAN I DO THAT
@SHAKEELHUSSAIN, how does your query string looks like ?
Request.QueryString["cityID"].ToString() (123456,654311,987654)
2

If your query string parameter value looks like: "123456,654311,987654"

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

Comments

0

try this it's so simple.

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

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

You get string like this "123456,654311,987654" in city. You get array in cityID.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.