将整数数组传递给URI参数中的WebAPI方法?

编程入门 行业动态 更新时间:2024-10-26 17:21:23
本文介绍了将整数数组传递给URI参数中的WebAPI方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下内容:

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

并且我正在尝试使用此:

and I'm trying to use this:

DELETE localhost:24144/api/folder/1483; DELETE 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:

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将为 mywebsite/api /mycontroller/findbymembers/?ids = 1& ids = 2& ids = 3 .

更多推荐

将整数数组传递给URI参数中的WebAPI方法?

本文发布于:2023-11-16 07:45:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1602352.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   数组   参数   方法   URI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!