Ajax.ActionLink呼叫控制器两倍两倍、控制器、Ajax、ActionLink

2023-09-10 14:11:03 作者:回眸ゝ淚傾城

当我点击Ajax.ActionLink是叫我的控制器的两倍。

 < TD ID = @ tdTag>
   @ Ajax.ActionLink(LL-+ item.getProjectAbbreviation(item.projectID.Value)+ - + item.prjLessonID,详细信息,
                    新{ID = item.lessonID},
                    新AjaxOptions
                        {
                          HttpMethod =POST
                          UpdateTargetId =细节,
                          InsertionMode = InsertionMode.InsertAfter,
                          的onSuccess =showDetails()

                         })
 

我的控制器看起来像这样...

 公众的ActionResult详细信息(INT ID)
    {
        使用(LLDataContext storeDB =新LLDataContext())
        {
            VAR教训=(从升的storeDB.lessons
                          其中,l.lessonID == ID
                          选择L).SingleOrDefault();

            返回PartialView(课);

        }
    }
 
如何在视图中使用ORDER BY短语

解决方案

我只是跑在这个同样的问题,我发现我不得不装两次jquery.unobtrusive-ajax.js。我删除了第二个实例,一切工作正常。要看到这个动作,只是将它加入三次,并创建一个@ Ajax.ActionLink(...)与确认AjaxOption。你会得到证实多次。

 <脚本SRC =@ Url.Content(〜/脚本/ jquery.unobtrusive-ajax.js)类型=文/ JavaScript的>< /脚本>
 

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

        }
    }

解决方案

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>