1

I would like to have a PUT-method that i can call with:

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

My route looks like this:

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

Then i tried the following method:

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

but if i try to call localhost/api/editRole/2 with some post-data i get The requested resource does not support http method 'PUT

What am i doing wrong?

Lord Vermillion
  • 5,264
  • 20
  • 69
  • 109

1 Answers1

4

You should mark your arguments with [FromUri] and [FromBody] attributes correspondingly:

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

Also your url localhost/api/editRole/2 should be like localhost/api/{controllerName}/2

Vitaliy Gorbenko
  • 490
  • 4
  • 14