0
我需要处理http://host.my/path?normal=1&othernormal=2&dict_a=b&dict_x=y
如何根据参数名称前缀从URL查询中绑定字典?
这是我在它的最新尝试,以关How to use Bind Prefix?:
public string Get(int normal, int othernormal,
[Bind(Prefix="dict_")]
Dictionary<string, string> dict) { ... }
,创建一个字典,但是,它是空的。
重要的是要注意,dict_a
和dict_x
是事先不知道的。例如。必须允许使用dict_abracadabra=bla
。
您需要的URL是'...&字典[0] =。重点B&字典[0] .value的= y'绑定到你的参数(不'[绑定(前缀=“dit _”)]'为什么不只是参数'字符串dict_a,字符串dict_x'并创建字典的值? –
@StephenMuecke,因为我不控制客户端。我的问题实际上有你的第二个答案 – LOST
您将需要从查询字符串中读取值(或者创建一个自定义模型联编程序来执行此操作),并根据值创建字典。 –