2016-04-28 4 views
1

にIDとPOSTデータの両方を渡す:MVCのWeb APIは、私は私が呼び出すことができるPUTメソッドを持っていると思います方法

localhost/api/editRole/id and pass post-data. 

私のルートは次のようになります。

routeTemplate: "api/{controller}/{action}/{id}" 

それから私は、次の方法を試みた。

[HttpPut] 
    public bool editRole(int id, roleDTO postdata) 
    { 
     return dal.editRole(postdata); 
    } 

をしかし、私はいくつかのポスト・データでlocalhost/api/editRole/2を呼び出そうと私はを取得します

私は間違っていますか?

+0

ようにすべきですか? –

+0

@Vermillionこの回答をチェック:http://stackoverflow.com/questions/23502198/web-api-405-the-requested-resource-does-not-support-http-method-put – gypsyCoder

答えて

2

あなたはそれに対応し[FromUri][FromBody]属性を使用して引数をマークする必要があります

[HttpPut] 
public bool editRole([FromUri] int id, [FromBody] roleDTO postdata) 
{ 
    return dal.editRole(postdata); 
} 

をまたあなたのURL localhost/api/editRole/2があなたのコントローラ名がlocalhost/API/editRole/2のURLにあるlocalhost/api/{controllerName}/2

関連する問題