2016-04-28 10 views
1

gibt Ich möchte eine PUT-Methode haben, die ich mit anrufen:MVC Web-API sowohl ID und POST-Daten Methode

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

Meine Route wie folgt aussieht:

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

dann habe ich versucht, die folgende Methode:

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

aber wenn ich versuche, localhost/api/editRole/2 mit einigen post-Daten zu nennen erhalte ich die requested resource does not support http method 'PUT

Was mache ich falsch?

+0

wo ist Ihr Controller-Namen in der URL localhost/api/editrole/2 enthalten sein sollte? –

+0

@ Vermillion überprüfen Sie diese Antwort: http://stackoverflow.com/questions/23502198/web-api-405-the-requested-resource-does-not-support-http-method-put – gypsyCoder

Antwort

2

Sie sollten Ihre Argumente mit [FromUri] und [FromBody] Attribute markieren entsprechend:

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

Auch localhost/api/editRole/2 Ihre URL wie localhost/api/{controllerName}/2