Asp.net mvc 如何根据参数名称前缀从URL查询绑定词典?

Asp.net mvc 如何根据参数名称前缀从URL查询绑定词典?,asp.net-mvc,asp.net-web-api,asp.net-core,Asp.net Mvc,Asp.net Web Api,Asp.net Core,我需要处理http://host.my/path?normal=1&othernormal=2&dict_a=b&dict_x=y 以下是我的最新尝试,基于: 公共字符串Get(int-normal,int-othernormal, [Bind(Prefix=“dict”)] 词典词典(Dictionary dict){…} 但是,它是空的 需要注意的是,dict_a和dict_x是事先未知的。例如,必须允许使用dict_abracadabra=bla。您可以将这些值绑定到字典,而无需绑定前缀

我需要处理
http://host.my/path?normal=1&othernormal=2&dict_a=b&dict_x=y

以下是我的最新尝试,基于:

公共字符串Get(int-normal,int-othernormal,
[Bind(Prefix=“dict”)]
词典词典(Dictionary dict){…}
但是,它是空的


需要注意的是,
dict_a
dict_x
是事先未知的。例如,必须允许使用
dict_abracadabra=bla

您可以将这些值绑定到字典,而无需绑定前缀。字典将使用querystring中的任何简单值

您的示例查询和方法签名(不带绑定前缀),它的工作方式与预期的基本相同:

我已经在MVC1.1.0-preview1-final中测试过了


从这里的文档中:

您需要url为
..&dict[0]。Key=b&dict[0]。Value=y
才能绑定到您的参数(不带
[bind(Prefix=“dit”)]
为什么不使用参数
字符串dict_a,字符串dict_x
并根据值创建字典?@StephenMuecke,因为我不控制客户端。我的问题实际上已经回答了第二个问题。您只需从查询字符串中读取值(或创建自定义模型绑定器即可)并根据这些值创建字典。
public string Get(int normal, int othernormal,
    [Bind(Prefix="dict_")]
    Dictionary<string, string> dict) { ... }