user1428642
user1428642

Reputation:

Getting all parameters into a Dictionary<string,string> in MVC3?

I would like to get the parameters from a URL into a Dictionary for the Controller. Here is an example:

URL:http://localhost/Application/View/Action?a=1&b=2

Controller Code

public ActionResult Action(Dictionary<string,string> args)
{
    //args["a"] = "1"
    //args["b"] = "2"
    return view(args); //sends entire dictionary
}

I have tried using extending the IValueProvider class but to no avail.

Upvotes: 1

Views: 1342

Answers (1)

YavgenyP
YavgenyP

Reputation: 2123

You can use the provided

Request.QueryString

to get those parameters. Its a NameValueCollection already (You can also access the keys there or iterate it as any other IEnumerable out there).

Upvotes: 2

Related Questions