【发布时间】:2016-11-16 10:35:52
【问题描述】:
我需要处理http://host.my/path?normal=1&othernormal=2&dict_a=b&dict_x=y
这是我最近的尝试,基于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 设为
...&dict[0].Key=b&dict[0].Value=y才能绑定到您的参数(没有[Bind(Prefix="dit_")]为什么不只是参数string dict_a, string dict_x并从值创建字典? -
@StephenMuecke,因为我不控制客户端。我的问题其实有你第二个问题的答案。
-
您只需要从查询字符串中读取值(或创建自定义模型绑定器来执行此操作)并根据值创建字典。
标签: asp.net-mvc asp.net-web-api asp.net-core