如何传递整数数组到一个asp.net网页API REST服务 [英] How to pass an array of integers to a asp.net web api rest service

查看:126
本文介绍了如何传递整数数组到一个asp.net网页API REST服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有asp.net的Web API REST服务,我需要传递一个整型数组。如何解决这个在asp.net中4个Web API来完成。

公开的IEnumerable<类别及GT; GetCategories(INT [] categoryIds){
// code,以从数据库中检索类别
}

URL访问上述服务

  /分类?c​​ategoryids = 1,2,3,4


解决方案

您只需要添加 [FromUri] 参数之前,看起来像

GetCategories([FromUri] INT [] categoryIds)

和请求发送:

  /分类categoryids = 1&安培; categoryids = 2及categoryids = 3

I have asp.net web api rest service where I need to pass an array of integers. How can this be done in asp.net 4 web api.

public IEnumerable<Category> GetCategories(int[] categoryIds){
// code to retrieve categories from database
}

Url to access the above service

/Categories?categoryids=1,2,3,4

解决方案

You just need to add [FromUri] before parameter, looks like:

GetCategories([FromUri] int[] categoryIds)

And send request:

/Categories?categoryids=1&categoryids=2&categoryids=3 

这篇关于如何传递整数数组到一个asp.net网页API REST服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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