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?

1
  • What have you tried? The first thing to try would be List<Termbasefile>>. Commented Mar 21, 2013 at 10:46

1 Answer 1

1

You need to implement a Post action that expects a list of that particular object type, or more specifically, an object which has the same properties e.g.

public class TermbaseFilePostDto
{
    // relevant properties go here
}


public class TestController : ApiController
{
     public HttpResponseMessage Post(List<TermbaseFileDto> list)
     {
         ...
     }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.