Alex Rivera | Logout

Ajax.ActionLink calling controller twice

Asked 2011-06-05T17:00:57.077
15

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);

        }
    }
Edit
Report

1 Answer

0

Make sure you have included the jquery unobtrusive script to your page (in addition to jquery):

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>

and that you have enabled unobtrusive javascript in your web.config

<add key="UnobtrusiveJavaScriptEnabled" value="true" />

Also to further diagnose such problems I would recommend you using some tool which would allow you to see exactly what happens at the HTTP level. FireBug is more than excellent for this kind of analysis. It will also show any possible javascript errors that you might have, it will show or not AJAX requests which will provide you with further information whether an AJAX request is performed or a normal request, ... useful stuff.

answered 2011-06-05T17:57:56.897

Your Answer