Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax.ActionLink calling controller twice

When I click on Ajax.ActionLink it is calling my controller twice.

<td id = @tdTag>
   @Ajax.ActionLink("LL-" + item.getProjectAbbreviation(item.projectID.Value) + "-" + item.prjLessonID, "Details",
                    new { id = item.lessonID },
                    new AjaxOptions
                        {
                          HttpMethod = "POST",
                          UpdateTargetId = "details",
                          InsertionMode = InsertionMode.InsertAfter ,
                          OnSuccess = "showDetails()"

                         }) 

My Controller looks like this...

   public ActionResult Details(int id)
    {
        using (LLDataContext storeDB = new LLDataContext())
        {
            var lesson = (from l in storeDB.lessons
                          where l.lessonID == id
                          select l).SingleOrDefault();

            return PartialView(lesson);

        }
    }
like image 708
marknery Avatar asked Jun 05 '11 17:06

marknery


1 Answers

I just ran in this same issue and I found that I had "jquery.unobtrusive-ajax.js" loaded twice. I removed the second instance and all is working well. To see this in action, just add it three times and create an @Ajax.ActionLink(...) with an Confirm AjaxOption. You will get confirmed multiple times.

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
like image 104
anAgent Avatar answered Sep 22 '22 04:09

anAgent