Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
La eliminación de JS AJAX falla

Este código se ejecuta correctamente, pero el problema es que no puedo comunicarme con el controlador para que realice la eliminación JS: se ejecuta sin errores y no se observan errores en Developer Tool. Pero el controlador en sí no se ejecuta.

JS

 jQueryAjaxDelete = form => { if (confirm('Are you sure to delete this record ?')) { try { $.ajax({ type: 'POST', url: form.action, data: new FormData(form), contentType: false, processData: false, success: function (res) { /*$('#view-all').html(res);*/ setTimeout(function () { location.reload(); }, 1000); }, error: function (err) { console.log(err) } }) } catch (ex) { console.log(ex) } } //prevent default form submit event return false;

}

Controlador

 [HttpPost] public async Task<ActionResult> CategoryDelete(int? id) { if (id == null) { return NotFound(); } var category = await _context.Categories.FindAsync(id); _context.Categories.Remove(category); await _context.SaveChangesAsync(); return Json(_context.Categories.ToList()); }

Vista

 <td><form asp-action="CategoryDelete" asp-route-id="@c.Id" onsubmit="return jQueryAjaxDelete(this)" class="d-inline"> <input type="submit" value="Delete" class="btn btn-danger" /> </form></td>

Herramienta para desarrolladores

[SOLUCIONADO] Necesita agregar enrutamiento a través de atributos [HttpPost], [HttpGet]

 [HttpGet("Admin/CategryDelete/{id}")]//here public ActionResult CategoryDelete() { return View(); } [HttpPost("Admin/CategryDelete/{id}")]//here public async Task<ActionResult> CategoryDelete(int? id) { if (id == null) { return NotFound(); } var category = await _context.Categories.FindAsync(id); _context.Categories.Remove(category); _context.SaveChanges(); return Json(_context.Categories.ToList()); }
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!