我创建了一个web api和一个mvc应用程序来使用api。在我的mvc员工控制器类中,我编写了代码来使用web api。但是,当我运行应用程序时,它会抛出一个异常,声明'System.Net.Http.Formatting.dll中出现类型'System.Net.Http.UnsupportedMediaTypeException'的异常,但未在用户代码中处理其他信息:否MediaTypeFormatter可用于从媒体类型为“text / html”的内容中读取“IEnumerable`1”类型的对象。下面是mvc应用程序控制器类代码。
public class EmployeeController : Controller
{
// GET: Employee
public ActionResult Index()
{
IEnumerable<mvcEmployeeModel> emplist;
HttpResponseMessage response = GlobalVariables.WebApiClient.GetAsync("Employee").Result;
emplist =response.Content.ReadAsAsync<IEnumerable<mvcEmployeeModel>>().Result;// gets exception here
return View(emplist);
}
}
}
请帮助解决这个问题。
将Content-Type:更改为'application/json
'或Content-Type:'application/xml
'
Content-Type:'application/json'
要么
Content-Type:'application/xml'