ASP.NET GET 参数与方括号



我不知道它们叫什么,这就是为什么我找不到解决方案。我有一个看起来像数组的查询字符串

params[name]=john&params[age]=25&params[country]=ru

有没有办法将这些参数解析为string[]Dictionary<string, string>

上级:在 php 上,这种类型的查询字符串使用

$params = $_GET['params']; $params['name']

但是我在 C# 上找不到等效项

如果使用 ASP.NET MVC 框架,则将查询字符串值转换为类型化参数的默认参数绑定程序可以通过以下方式自动处理它:

一维数组

// GetData?filters[0]=v1&filters[1]=v2&filters[3]=v3
public ActionResult GetData(IEnumerable<string> filters) 
{
    // todo
}

二维数组

// GetData?filters[0][field]=name&filters[0][type]=1&filters[0][value]=val
public ActionResult GetData(IEnumerable<Dictionary<string,string>> filters) 
{
    // todo
}

。等等。

有关更多信息和示例,请查看我就此主题撰写的这篇博客文章。