Execute Action Post by JQuery ASP.NET MVC

0

I would like to delete a record in a button click by Jquery, what is the best way to do it? The way I did it is not working.

  

Action I want to call by Jquery

        // POST: Pais/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Pais pais = db.Paises.Find(id);
            pais.Delete();
            return RedirectToAction("Index");
        }
  

Event in Jquery where I want to call Action DeleteConfirmed

 $('.btnExcluirSimPopover').on('click', function () {
    if (handlePopover > 0) {
      $.post("/Pais/DeleteConfirmed", { id: handlePopover }, function (data){

      });
    }
 });
    
asked by anonymous 25.10.2017 / 18:43

1 answer

1

Data annotation ActionName is overwriting the name of your action DeleteConfirmed to Delete . Change that name in your call that should work.

 $('.btnExcluirSimPopover').on('click', function () {
    if (handlePopover > 0) {
      $.post("/Pais/Delete", { id: handlePopover }, function (data){

      });
    }
 });
    
25.10.2017 / 18:50