4

我在我的 MVC 4 应用程序中使用 ASP.Net Web API 来执行各种操作。问题是我的 API 方法返回动态类型,而在 View 端我正在使用该方法ReadAsAsync().Result。现在我怎样才能在视图端获得我的 API 结果。

我的 API 代码如下:

public dynamic GetSum(int a,int b)
{ return a + b; }

视图端代码如下:

HttpResponseMessage response = client.GetAsync(String.Format("/webApi/Common/GetSum?a=`{1}&b={2}", 1,1);`
if (response.IsSuccessStatusCode)
{
    dynamic temp = response.Content.ReadAsAsync<dynamic>().Result;
    return view(temp);
}

return view();

请帮助我,我陷入了这个问题。

4

1 回答 1

3

你可以ExpandoObject用来获取dynamic数据

dynamic temp = response.Content.ReadAsAsync<ExpandoObject>().Result;
于 2016-07-21T15:08:08.903 回答