0

I have a WindowsForm application and i want to send an List<> to the Web API

here is my code in the windows form app:

        Uri uri = new Uri("http://localhost/test/api/v1/name/testcontroller/");

        HttpClient client = new HttpClient();

        client.BaseAddress = uri;

        var mediaType = new MediaTypeHeaderValue("application/json");
        var jsonFormatter = new JsonMediaTypeFormatter();

        HttpContent content = new ObjectContent<List<TermbaseFile>>(termbaseList, jsonFormatter);
        HttpResponseMessage responseMessage = client.PostAsync(uri, content).Result;

What should i put in the controller-method to get the List?

4

1 回答 1

1

您需要实现一个Post动作,该动作需要一个特定对象类型的列表,或者更具体地说,一个具有相同属性的对象,例如

public class TermbaseFilePostDto
{
    // relevant properties go here
}


public class TestController : ApiController
{
     public HttpResponseMessage Post(List<TermbaseFileDto> list)
     {
         ...
     }
}
于 2013-03-21T10:47:41.650 回答