C# 在ASP.NET Web Api中实现对Restangulars.multiple()方法的支持

C# 在ASP.NET Web Api中实现对Restangulars.multiple()方法的支持,c#,asp.net,rest,asp.net-web-api,restangular,C#,Asp.net,Rest,Asp.net Web Api,Restangular,我最近在restanglar中找到了方便的方法。 这使我能够获取多个单个对象,非常好 因此,我尝试了以下restanglar.几个('accounts','a','b','c')

我最近在restanglar中找到了方便的方法。 这使我能够获取多个单个对象,非常好

因此,我尝试了以下
restanglar.几个('accounts','a','b','c')/api/accounts/a、b、c

这与我的ASP.NET Web Api控制器不太匹配。 初稿:

public class MyController : ApiController
{
    public HttpResponseMessage GetAll() { ... }
    public HttpResponseMessage GetSingle(string id) { ... }
    public HttpResponseMessage GetMultiple(IEnumerable<string> ids) { ... }
}
现在它没有崩溃。但是
id
a、b、c

我真的需要手动
拆分
字符串并从那里使用它吗?
这也不适用于
int
类型<代码>公共HttpResponseMessage GetSingle(int-id){…}


在ASP.NET Web Api中实现
.multive()
支持的正确方法是什么?我假设这是一个标准的REST调用,因为它在restanglar中。

带有正则表达式约束的属性路由可以在这里工作

[Route("api/my")]
public HttpResponseMessage GetAll() {
    // ...
}

[Route("api/my/{id:regex(^[^,]+$)}")]
public HttpResponseMessage GetSingle(string id)
{
    // ...
}

[Route("api/my/{ids:regex(,)}")]
public HttpResponseMessage GetMultiple(string ids)
{
    // strings
    var idList = ids.Split(',');

    //// ints
    // var idList = ids.Split(',').Select(i => Convert.ToInt32(i)).ToList();

    // ...
}

还没有真正研究过路由属性,也许我应该-谢谢:)顺便说一句,您可以像这样强制转换
ids.Split(',').cast()
[Route("api/my")]
public HttpResponseMessage GetAll() {
    // ...
}

[Route("api/my/{id:regex(^[^,]+$)}")]
public HttpResponseMessage GetSingle(string id)
{
    // ...
}

[Route("api/my/{ids:regex(,)}")]
public HttpResponseMessage GetMultiple(string ids)
{
    // strings
    var idList = ids.Split(',');

    //// ints
    // var idList = ids.Split(',').Select(i => Convert.ToInt32(i)).ToList();

    // ...
}