Ajax.ActionLink呼叫控制器两倍 [英] Ajax.ActionLink calling controller twice

查看:97
本文介绍了Ajax.ActionLink呼叫控制器两倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击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(课);

        }
    }
 

解决方案

我只是跑在这个同样的问题,我发现我不得不装两次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>

这篇关于Ajax.ActionLink呼叫控制器两倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆