将整数数组传递给URI参数中的WebAPI方法? [英] Passing array of integers to WebAPI method in URI params?

查看:215
本文介绍了将整数数组传递给URI参数中的WebAPI方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容:

    [HttpDelete]
    public HttpResponseMessage DeleteFolder(int[] ids)
    {

并且我正在尝试使用此:

and I'm trying to use this:

DELETE http://localhost:24144/api/folder/1483;
DELETE http://localhost:24144/api/folder/[1483]

但是这些在delete方法中显示为null-我如何发送数据而不将其放在正文中(因为这是一个DELETE请求)?

but these are coming up as null within the delete method - how do I send the data without putting it in the body (since this is a DELETE request)?

我的路线有这个:

            routes.MapHttpRoute(
           name: "Folder",
           routeTemplate: "api/folder/{id}",
           defaults: new { controller = "Folder", id = RouteParameter.Optional }
            );

推荐答案

没关系,我发现了这一点:

Nevermind, I found this:

http://blog.codelab.co.nz/2012/10/16/passing-arrays-into-asp-net-web-api-as-parameters/

虽然找不到关于SO的答案,所以我将其留在这里.

Couldn't find an answer on SO though so I'll leave it here.

从上面的链接页面摘录:

[HttpGet()]
public HttpResponseMessage FindByMembers([FromUri]Int32[] ids = null)
{
   //Do stuff
    return Request.CreateResponseMessage(HttpStatusCode.OK);
}

Url将为 http://mywebsite/api /mycontroller/findbymembers/?ids = 1& ids = 2& ids = 3 .

这篇关于将整数数组传递给URI参数中的WebAPI方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆