BDC
BDC

Reputation: 110

How do you access all querystring parameters as a dictionary

I have some dynamic querystring parameters that I would like to interact with as an IDictionary<string,string> or similar? How do I do this?

For example. How can I interpret multiple (varying in quantity) variables for a query similar to:

/{area}/{controller}/{action}?alert=primary&msg=Success

Parallel question for asp.net-web-api

Upvotes: 1

Views: 1396

Answers (1)

BDC
BDC

Reputation: 110

You can use the Query method on the AspNetCore.Http.DefaultHttpRequest to get the parsed query string as a collection of key-value pairs.

public IActionResult Get()
{
    var queryString = this.Request.Query;
}

Additionally, How to read values from the QueryString provides a nice summary of the methods to access and use the IQueryCollection that is created in this approach.

Specifically: ToString() and Inclusion in Method Parameter List.

Upvotes: 2

Related Questions