정수 목록을 C# 컨트롤러 동작에 전달하려고합니다. 나는 다음과 같은 코드가 있습니다 :정수 목록을 C# 컨트롤러 동작에 전달하십시오.
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);
컨트롤러 액션 : 결과 responseString
는 그러나
[HttpPost]
[ActionName("getData")]
public Response getData(List<int> myInts) {
// ...
}
:
{"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}
답변 중 하나가 도움이 되었다면, 답변을 upvote하고 표시하십시오. 귀하의 질문에 여전히 답이 없으면 저희에게 알려주십시오. 질문에 대한 다른 답변을 찾은 경우 답으로 게시하십시오. 감사! :) – pcdev