title: ASP.NET Web API Put request unable to find method in controller
body: <p>I am trying to update the value of an album using a web api service, but when I use the put request it gets to the controller (sometimes), creates the context, but is then doesn't find/run the PUT method I have.</p>
  
  <p>I'm sending the class Album (below), formatted as JSON to Web API.</p>
  
  <pre><code>public class Album
  {
      [ScaffoldColumn(false)]
      public int Id { get; set; }
  
      [Required]
      public string Title { get; set; }
  
      public string Description { get; set; }
  
      [Required]
      public string Artist { get; set; }
  
      public string Genre { get; set; }
  
      [Required]
      public int Year { get; set; }
  
      [Display(Name="No. Tracks")]
      public int NumberOfTracks { get; set; }
  }
  </code></pre>
  
  <p>This is the WebAPI controller that should be receiving it all</p>
  
  <pre><code>public class AlbumsController : ApiController
  {
      private AlbumsContext db = new AlbumsContext();
  
      // GET api/Albums
  
      public IQueryable&lt;Album&gt; Get()
      {
          return (from a in db.Albums select a);
      }
  
      public IQueryable&lt;Album&gt; Get(int skip, int page)
      {
          var ret = (from a in db.Albums select a);
          ret = ret.OrderBy(a =&gt; a.Title);
          ret = ret.Skip(skip);
          ret = ret.Take(page);
          return ret;
      }
  
      // GET api/Albums/5
      public Album Get(int id)
      {
          return db.Albums.FirstOrDefault(a =&gt; a.Id == id);
      }
  
      // PUT api/Albums
      [HttpPut]
      public HttpResponseMessage Put([FromBody]Album album)
      {
          if (!ModelState.IsValid)
          {
              return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
          }
  
          db.Entry(album).State = EntityState.Modified;
  
          try
          {
              db.SaveChanges();
          }
          catch (DbUpdateConcurrencyException ex)
          {
              return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
          }
  
          return Request.CreateResponse(HttpStatusCode.OK);
      }
  
      // POST api/Albums
      public HttpResponseMessage Post(Album album)
      {
          if (ModelState.IsValid)
          {
              db.Albums.Add(album);
              db.SaveChanges();
  
              HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, album);
              response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = album.Id }));
              return response;
          }
          else
          {
              return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
          }
      }
  
      // DELETE api/Albums/5
      public HttpResponseMessage Delete(int id)
      {
          Album album = db.Albums.Find(id);
          if (album == null)
          {
              return Request.CreateResponse(HttpStatusCode.NotFound);
          }
  
          db.Albums.Remove(album);
  
          try
          {
              db.SaveChanges();
          }
          catch (DbUpdateConcurrencyException ex)
          {
              return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
          }
  
          return Request.CreateResponse(HttpStatusCode.OK, album);
      }
  
      protected override void Dispose(bool disposing)
      {
          db.Dispose();
          base.Dispose(disposing);
      }
  }
  </code></pre>
  
  <p>And this is the Server controller method making the PUT request</p>
  
  <pre><code>[HttpPut]
  public ActionResult Edit(Album album, HttpPostedFileBase Image1, HttpPostedFileBase Image2, HttpPostedFileBase Image3, int AlbumID, int RemoveID = 0)
  {
      string AlbumApiUri = "http://localhost:58431/api/Albums";
  
      HttpRequestMessage request = new HttpRequestMessage();
  
      request.RequestUri = new Uri(AlbumApiUri);
  
      request.Method = HttpMethod.Put;
  
      MediaTypeFormatter jsonFormatter = new JsonMediaTypeFormatter();
  
      request.Content = new ObjectContent&lt;Album&gt;(album, jsonFormatter);
  
      request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
  
      album.Id = AlbumID;
  
      HttpClient client = new HttpClient();
  
      var response = client.SendAsync(request).Result;
  
      if (response.IsSuccessStatusCode)
      {
          bool a = true;
      }
      else
      {
          bool b = true;
      }
  
      return RedirectToAction("Details", new { ID = AlbumID });
  }
  </code></pre>