title: Trying to get window.location.href to call ActionResult. MVC + Javascript
body: <p>I have a delete button that calls a javascript function onclick.
  The function function fires, gets id and displays in Alert, the tries to use window.location.href = "/Home/DeletePhoto/photoId=" + id; to call an ActionResult in the HomeController.</p>
  
  <p>button in modal popup:</p>
  
  <pre><code> &lt;button class="title" id="btnDelete" onclick="fDoTheDelete();"&gt;Delete&lt;/button&gt;
  </code></pre>
  
  <p>javascript function at the bottom of the View:</p>
  
  <pre><code>   function fDoTheDelete()
      {
         alert("in the delete function: " + document.getElementById('h3Title').innerHTML);
  
         var id = document.getElementById('h3Title').innerHTML;
  
         window.location.href = "http://localhost:50061/Home/DeletePhoto/photoId=" + id;
      }
  </code></pre>
  
  <p>(if I Ctrl + Click on the URL below in the javascript code, it runs the ActionResult as required)</p>
  
  <pre><code>window.location.href = "http://localhost:50061/Home/DeletePhoto/photoId=" + id;
  </code></pre>
  
  <p>Here is the ActionResult. I want to delete a photo and it's record and redirect to Home/Index which will display photos without the deleted one.</p>
  
  <pre><code>   public ActionResult DeletePhoto(int photoId)
          {
          //GET FILENAME FROM ID
         string photoName = (from p in db.Photos
                          where p.PhotoId == photoId
                          select p.Description).FirstOrDefault();
  
          //DELETE FILE
  
          string fullPath = "/GalleryImages /" + photoName;
  
          if (System.IO.File.Exists(fullPath))
              {
              System.IO.File.Delete(fullPath);
              }
  
          //DELETE RECORD OF PHOTO
  
          Photo photo = db.Photos.Find(photoId);
          db.Photos.Remove(photo);
          db.SaveChanges();
  
  
          return RedirectToAction("Index");
  
          }
  </code></pre>
  
  <p>On button click, Alerts show that I am inside javascript function, and the id has been passed, but the photo Modal window just closes and displays same Index showing the thumbnail of the image still exists.</p>
  
  <p><strong>EDIT:</strong>
  I came back to edit and add the information that I am using <a href="http://www.advancesharp.com/blog/1130/image-gallery-in-asp-net-mvc-with-multiple-file-and-size" rel="nofollow noreferrer">This image gallery</a> which was very easy to configure but made it difficult to pass additional stuff between the thumbnail/index display and the Modal lightbox popup. That is why I am having so much trouble with a simple call to an ActionResult. There is lots of js/jquery/blueimp code that is difficult to hack.
  thanks for everyone that made an effort to help me and I hope someone else can use the Image Gallery too.</p>