5

I know that if I have an url like XController/Action?id=1, and an action method

void Action(int id)

the id parameter will automatically be read from the query string.

But how can I access the entire query string when I don't in advance know the name of all parameters. E.g:

void Action(QueryStringCollection coll) {
    object id = coll["id"];
}

Is it possible to do something like this?

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
erikkallen
  • 33,800
  • 13
  • 85
  • 120

1 Answers1

11

Use Request.QueryString for this

Request.QueryString.Keys gives you the name of all parameters

eu-ge-ne
  • 28,023
  • 6
  • 71
  • 62
  • The only draw back to using Request is you lose the ability to do unit testing on your controller actions without building up a HttpContext. It's just one of those things were another method doesn't exist and the pros usualy outweigh the cons. – Nick Bork Feb 25 '12 at 03:42