title: How to delete a record in MVC without using a View?
body: <p>Normally I put the following in my Index view:</p>
  
  <pre><code>@Html.ActionLink(" ", "Delete", new { id = item.UserId }, new { onclick = "return confirm('Are you sure you want to delete this user?');", @class = "delete-button" })
  </code></pre>
  
  <p>This allows me to delete the item inline on table without having navigate away from my listing. All I need to do is confirm the delete through the javascript confirm.</p>
  
  <p>My action looks like this:</p>
  
  <pre><code>public ActionResult Delete(int id)
  {
      User user = db.Users.Find(id);
      if (user == null)
      {
          return HttpNotFound();
      }
      else
      {
          db.Users.Remove(user);
          db.SaveChanges();
          return RedirectToAction("Index");
      }
  }
  </code></pre>
  
  <p>I'm now trying the same thing but with a linkage to my web service which will process the delete on the database.</p>
  
  <p>The only difference is in the controller which now looks like this:</p>
  
  <pre><code>private async Task&lt;ActionResult&gt; Delete(int id)
  {
      string url = String.Format("api/user/{0}", id);
  
      using (HttpClient client = new HttpClient())
      {
          client.BaseAddress = new Uri("http://localhost:49474/");
          client.DefaultRequestHeaders.Accept.Clear();
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
          HttpResponseMessage response = await client.DeleteAsync(url);
  
          return RedirectToAction("Index");
      }
  }
  </code></pre>
  
  <p>Just to be thorough, here's the web service code to delete the record:</p>
  
  <pre><code>public HttpResponseMessage Delete(int id)
  {
      try
      {
          var existing = db.Users.Find(id);
  
          if (existing != null)
          {
              db.Users.Remove(existing);
              db.SaveChanges();
  
              HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
  
              return response;
          }
          else
          {
              throw new ArgumentNullException("Object ID not found");
          }
  
      }
      catch (Exception ex)
      {
          return ReportError(ex, "DELETE USER");
      }
  }
  </code></pre>
  
  <p>This gives me the javascript confirm but the delete doesn't happen on the database and I get an error screen that says no view exists.</p>
  
  <p>Upon debugging, I find that the functions above aren't even requested. I feel like I need to add something into the controller, but I'm not sure what.</p>