title: Delete link with jquery confirm in Asp.Net MVC 2 application
body: <p>I have a table with records that has delete links. Basically I followed the NerdDinner tutorial for that part in MVC. But I don't want to have the confirm view, I'd rather have a confirm dialog, and then if confirmed let the HttPost action method delete the record directly.</p>
  
  <p>I have something working, but being new to both MVC and jQuery, I'm not sure if I'm doing it right.</p>
  
  <p>Here's the jQuery:</p>
  
  <pre><code>    $(function () {
          $('.delete').click(function () {
              var answer = confirm('Do you want to delete this record?');
              if (answer) {
                  $.post(this.href, function () {
                      window.location.reload(); //Callback
                  });
                  return false;
              }
              return false;
          });
      });
  </code></pre>
  
  <p>And the delete actionlink:</p>
  
  <pre><code>&lt;%: Html.ActionLink("Delete", "Delete", new { id = user.UserID }, new { @class = "delete" })%&gt;
  </code></pre>
  
  <p>And finally, the delete action method:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Delete(int id)
      {
          _db = new UsersEntities();
          try
          {
              //First delete the dependency relationship:
              DeleteUserVisits(id);
              //Then delete the user object itself:
              DeleteUser(id);
          }
          catch (Exception)
          {
              return View("NotFound");
          }
  
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>Now, I have a few questions about this:</p>
  
  <ol>
  <li><p>I found the function for making the link POST instead of GET on the internet: `$.post(this.href); return false; And I'm not sure what the "return false" part does. I tried to modify it for my needs with a callback and so on, and kept the return part without knowing what it's for.</p></li>
  <li><p>Secondly, the action method has the HttpPost attribute, but I have also read somewhere that you can use a delete verb. Should you? And what about the RedirectToAction? The purpose of that was originally to refresh the page, but that didn't work, so I added the window.location.reload instead in a callback in the jQuery. Any thoughts?</p></li>
  <li><p>The Delete action method calls a couple of helper methods because it seems with the Entity Framework that I use for data, I can't just delete an record if it has relationship dependencies. I had to first delete the relationships and then the "User" record itself. That works fine, but I would have thought it would be possible to just delete a record and all the relationships would be automatically deleted...?</p></li>
  <li><p>I know you're not supposed to just delete with links directly because crawlers etc could accidentally be deleting records. But with the jQuery, are there any security issues with this? Crawlers couldn't do that when there is a jQuery check in between, right?</p></li>
  </ol>
  
  <p>Any clarifications would be greatly appreciated!</p>