I started to study a little web api using with asp.net, I am doing a very simple example where I just want to list the data of the employee table, but I get error: No MediaTypeFormatter is available to read an object of type 'IEnumerable'1' from content with media type 'text / html'.
public static class GlobalVariables
{
public static HttpClient WebApiClient = new HttpClient();
static GlobalVariables()
{
WebApiClient.BaseAddress = new Uri("http://localhost:57129/api");
WebApiClient.DefaultRequestHeaders.Clear();
WebApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
}
Controler Index
public ActionResult Index()
{
IEnumerable<MvcEmpregadosModel> empregadoLista;
HttpResponseMessage response = GlobalVariables.WebApiClient.GetAsync("Empregados").Result;
empregadoLista = response.Content.ReadAsAsync<IEnumerable<MvcEmpregadosModel>>().Result;
return View(empregadoLista);
}