title: No MediaTypeFormatter is available to read an object of type 'IEnumerable`1' from content with media type 'text/html in asp.net mvc webapi
body: <p>I'm creating an ASP.NET MVC web application using Web API and ASP.NET MVC together. I get this error:</p>
  
  <blockquote>
    <p>No MediaTypeFormatter is available to read an object of type 'IEnumerable`1' from content with media type 'text/html</p>
  </blockquote>
  
  <p>studentController (mvcproject)</p>
  
  <pre><code>namespace Mvcproj.Controllers
  {
     public class studentController : Controller
     {
          public static HttpClient client = new HttpClient();
  
          // GET: Employes
          public ActionResult Index()
          {
              client.BaseAddress = new Uri("http://localhost:1747/api");
              client.DefaultRequestHeaders.Clear();
              client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
              IEnumerable&lt;studmodel&gt; emplist;
              HttpResponseMessage response = client.GetAsync("studen").Result;
              Response.ContentType = "application/json";
              emplist = response.Content.ReadAsAsync&lt;IEnumerable&lt;studmodel&gt;&gt;().Result;          //here get an error
              response.EnsureSuccessStatusCode();
              return View(emplist);
          }
      }
  }
  </code></pre>
  
  <p>Index.cshtml</p>
  
  <pre><code>@model IEnumerable&lt;Mvcproj.Models.studmodel&gt;
  
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  &lt;/p&gt;
  &lt;table class="table"&gt;
      &lt;tr&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.studid)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.username)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.password)
          &lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
  @foreach (var item in Model) {
      &lt;tr&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.studid)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.username)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.password)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
              @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
              @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  
  &lt;/table&gt;
  </code></pre>
  
  <p>Output:</p>
  
  <p><a href="http://localhost:1785/studen/index" rel="nofollow noreferrer">http://localhost:1785/studen/index</a></p>
  
  <p>studentController (api project)</p>
  
  <pre><code>namespace WebsApi.Controllers
  {
      public class studentController : ApiController
      {
          private studangEntities db = new studangEntities();
  
          // GET: api/studen
          public IQueryable&lt;student&gt; Getstudents()
          {
              return db.students;
          }
  
          // GET: api/studen/5
          [ResponseType(typeof(student))]
          public IHttpActionResult Getstudent(int id)
          {
              student student = db.students.Find(id);
              if (student == null)
              {
                  return NotFound();
              }
  
              return Ok(student);
          }
        }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <p><a href="http://localhost:1747/api/studen" rel="nofollow noreferrer">http://localhost:1747/api/studen</a></p>
  
  <pre><code>&lt;ArrayOfstudent xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WebsApi.Models"&gt;
      &lt;student&gt;
          &lt;password&gt;admin@123&lt;/password&gt;
          &lt;studid&gt;1017&lt;/studid&gt;
          &lt;username&gt;admin&lt;/username&gt;
      &lt;/student&gt;
      &lt;student&gt;
          &lt;password&gt;devis&lt;/password&gt;
          &lt;studid&gt;1025&lt;/studid&gt;
          &lt;username&gt;devis&lt;/username&gt;
      &lt;/student&gt;
  </code></pre>
  
  <p>I also changed <code>application/xml</code> - but that's causing the same error.</p>
  
  <p>When I'm debugging:</p>
  
  <pre><code>content  {System.Net.Http.StreamContent}
  
  status code  System.Net.HttpStatusCode.NotFound
  
  requestmessage {Method: GET, RequestUri: 'http://localhost:1747/studen', Version: 1.1, Content: &lt;null&gt;, Headers:
  {
  Accept: text/json
  }}
  </code></pre>
  
  <p>I'm referring to this article: <a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/media-formatters" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/media-formatters</a>       but error not solved</p>
  
  <p>how to solve this error??</p>