2013-07-22 98 views
4

我有以下幾點:在URI參數中將整數數組傳遞給WebAPI方法?

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

,我嘗試使用此:

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

但這些都上來了刪除方法中爲空 - 如何發送數據,而無需投入它在體內(因爲這是一個DELETE請求)?

我的路由具有這樣的:

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

另請參閱http://stackoverflow.com/q/9981330/1405720 – mjohnsonengr

回答

0

,如果你正在尋找有烏里像api/folder/[1,2,3],在下面的文章的答覆中提到的相同參數綁定的例子可以用在這裏太:

How to send an array via a URI using Attribute Routing in Web API?

注意:您將需要將以下行更改爲'id'路由變量而不是'id',因爲您的路由模板是'api/folder/{id}'。

string idsAsString = actionContext.Request.GetRouteData().Values["id"].ToString();