如何在ASP.net控制器操作中访问整个查询字符串

eri*_*len 5 asp.net-mvc controller query-string

我知道如果我有一个像XController/Action?id = 1的url,还有一个action方法

void Action(int id)
Run Code Online (Sandbox Code Playgroud)

将自动从查询字符串中读取id参数.

但是,当我事先没有知道所有参数的名称时,如何访问整个查询字符串.例如:

void Action(QueryStringCollection coll) {
    object id = coll["id"];
}
Run Code Online (Sandbox Code Playgroud)

可以这样做吗?

eu-*_*-ne 11

为此使用Request.QueryString

Request.QueryString.Keys为您提供所有参数的名称