0

I am trying to understand the GetValues for Form and QueryString in context.Request

I have a url like this, generated from an ajax handler on a multiple select html element

generic.ashx?tags=1&tags=2

in theory shouldnt this (submitted by post) set the string tags to 1, 2?

string[] tags = context.Request.Form.GetValues("tags");

I have tried using the get method as well, using querystring or just context request, nothing so far

string[] tags = context.Request.QueryString.GetValues("tags");
string[] tags = context.Request.GetValues("tags");

My bottom line is i want to build a sql where clause

int tagscount = tags.Count();

      string sWhere ="";

        if (tagscount != 0) {
          sWhere ="Where (";
          for (int i = 0; i < tagscount; i++)

            {

                sWhere += " tag_id ="+tags[i]+")";
                if (i < tagscount -1){
                  sWhere += " OR ";
                }

              }
              sWhere += ")";
            }

but honestly i would just be thrilled at this point to show that my string is being populated

results = string.Format("{{ \"tags\": {0}  }}",tags);
context.Response.Write(results);
Jay Rizzi
  • 4,196
  • 5
  • 42
  • 71
  • Are you sure that this doesn't populate the array with the two values you're expecting? var tags = context.Request.QueryString.GetValues("tags"); – Ian Gilroy Mar 31 '15 at 15:31

1 Answers1

1

GetValues() should work, instead of strictly getting values into string[], try using var and iterate to get each value from it.

var values = context.Request.QueryString.GetValues("tags");
foreach (var item in values)
{
    //do your thing
}
Chaitanya Gadkari
  • 2,669
  • 4
  • 30
  • 54