I have an @Ajax.ActionLink that I am using to delete a record form my database. When I click the link, my page asks for a confirmation, deletes the course, and refreshes the div that contains the table of records. I want to use AJAX in jquery instead of using the action link. When I click my delete button, I get my confirmation box, click ok and then nothing happens. I know my jquery function is getting the correct values from the row selected because I had them output to make sure. I can't figure out why the ajax never runs but the action link works fine. Below is my code for both and my controller
Controller:
public PartialViewResult deleteCourses(string stuId, string courseAbNum) { KuPlanEntities db = new KuPlanEntities(); var deleteCourse = (from course in db.COURSE_TAKEN where course.courseAbNum == courseAbNum && course.Id == stuId select course); foreach (var course in deleteCourse) { db.COURSE_TAKEN.Remove(course); db.SaveChanges(); } var stuCourses = (from studCourse in db.COURSE_TAKEN join course in db.COURSEs on studCourse.courseAbNum equals course.courseAbNum where studCourse.Id == stuId select new courseTakenView { Id = studCourse.Id, courseAbNum = studCourse.courseAbNum, status = studCourse.status, grade = studCourse.grade, courseDesc = course.courseDesc, credits = course.credits, rowNum = studCourse.rowNum }); var model = new courseListViewModel { userId = stuId, courseTaken = stuCourses }; return PartialView("~/Views/ManageStudentCourses/listCourseRefresh.cshtml",model); } Action link:
@Ajax.ActionLink("Delete", "deleteCourses", new { stuId = Model.userId, courseAbNum = @course.courseAbNum }, new AjaxOptions { UpdateTargetId = "refreshList", Confirm = ("Are you sure you want to delete this course?") }) jquery:
$(document).ready(function () { $('.deleteCourseBtn').click(function () { if(confirm("Are you sure you want to delete this course?")) { var courseAbNum = $(this).attr('data-id'); var stuId = $('#userId').val(); $.ajax({ type: 'POST', url: '/ManageStudentCourses/deleteCourses', data: { stuId:stuId, courseAbNum:courseAbNum }, dataType: 'html' .success(function (result) { $('#refreshList').html(result); }) }); } else { return false; } }) });