I am trying to pass in a list of integers to a C# controller action. I have the following code:
HttpRequestMessage request;
String myUrl = 'http://path/to/getData';
List<int> data = new List<int>() { 4, 6, 1 };
request = new HttpRequestMessage(HttpMethod.post, myUrl);
request.Content = new StringContent(JsonConvert.SerializeObject(data, Formatting.Indented));
HttpResponseMessage response = httpClient.SendAsync(request).Result;
String responseString = response.Content.ReadAsStringAsync().Result;
var data = (new JavaScriptSerializer()).Deserialize<Dictionary<string, object>>(responseString);
The controller action:
[HttpPost]
[ActionName("getData")]
public Response getData(List<int> myInts) {
// ...
}
However the resulting responseString
is:
{"Message":"An error has occurred.","ExceptionMessage":"No MediaTypeFormatter is available to read an object of type 'List`1' from content with media type 'text/plain'.","ExceptionType":"System.InvalidOperationException}