[問題] ASP.NET Web API 2參數如何接收array
目前正在製作Web API 2的WebService,
GET, POST都能夠順利收到前端傳過來的資料,
不過前端現在需求有可能會要傳相同的資料數筆,
如:一次傳多筆學生的個人資料..
我的方法如下:(示意)
[HttpPost]
public IHttpActionResult AddStudentData(AddStudentParams[] paramAddStudent)
不過檢查paramAddStudent得到的Lenth為0,
是不是WebApiConfig.cs內的routing也要新增呢?
再麻煩板友回覆,網上查到關於傳Array的routing設定很少..
謝謝。
--
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.34.236.60
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1510314607.A.9AD.html
→
11/10 21:10,
7年前
, 1F
11/10 21:10, 1F
→
11/12 14:19,
7年前
, 2F
11/12 14:19, 2F
代碼
--
[HttpPost]
public int AssignMemberToGroup(int[] paramGo)
{
int total = 0;
var results = new List<int>();
for (var i = 0; i < paramGo.Length; i++)
{
var temp = new int();
temp = paramGo[i];
results.Add(temp);
}
return total;
}
--
參照網上搜到的...
https://stackoverflow.com/questions/34314306/webapi-passing-an-array-of-values
※ 編輯: james999 (1.34.236.60), 11/12/2017 14:35:04
推
11/13 06:06,
7年前
, 3F
11/13 06:06, 3F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章