WebApi Put,如何通过params?

时间:2015-01-26 18:09:14

标签: asp.net-web-api

我创建了一个webApi,可以自动为我创建som方法。 Put-Method就是这样创建的:

 // PUT: api/Actor/5
    [ResponseType(typeof(void))]
    public async Task<IHttpActionResult> PutActor(int id, Actor actor)
    {
        //Code that updates the actor
    }

但我怎么称呼这种方法? 我认为它必须从:

开始
HttpResponseMessage response =  client.PutAsJsonAsync("api/Actors/")  <-How can i add the two params?

根据一些帖子,你无法做到没有解决方法:

WebAPI Multiple Put/Post parameters

但考虑到该方法是自动创建的,这似乎很奇怪。应该是一个标准的方法吗?

1 个答案:

答案 0 :(得分:0)

您可以在路由中传递id,而使用following overload作为第二个参数作为对象的有效负载中的Actor:

HttpResponseMessage response = client.PutAsJsonAsync("api/Actors/123", new 
{
    actor = new Actor
    {
        Name = "John Smith",
        Age = 30,
    }
});