【发布时间】:2018-04-19 19:15:06
【问题描述】:
我正在编写 asp.net mvc 5 web api。我有以下代码,我想像http://localhost/API/Compatibility/59dd2c60-c340-4735-8ecb-85efc60c7b14;d126d9b3-4516-46ca-bd6c-1a8c23740b90一样调用web api
[RoutePrefix("API/Compatibility")]
public class CompatibilityController : ApiController
{
[Route("{organizationIds}")]
public Guid Get(IList<Guid> organizationIds)
{
...
}
}
当前参数organizationIds 无法从 URL 接收值。我理解这是因为默认模型绑定器不知道如何分隔 GUID。
自定义模型绑定器似乎是救命稻草。
我的其他 web api 可能使用分号以外的不同分隔符。因此,与其创建SemicolonSeparatedBinder、CommaSeparatedBinder、PipeSeparatedBinder 等,我可以创建SymbolSeparatedBinder 并传入分隔符吗?
这样可以吗?
[Route("{organizationIds}")]
public Guid Get([ModelBinder(typeof(SymbolSeparatedBinder), separator=";")]
IList<string> organizationIds)
{
...
}
【问题讨论】: