Ajax.ActionLink呼叫控制器两倍

编程入门 行业动态 更新时间:2024-10-28 04:17:23
本文介绍了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呼叫控制器两倍

本文发布于:2023-10-09 10:19:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1475473.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两倍   控制器   Ajax   ActionLink

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!