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);
}
}
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>
use either of only one js not both one
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")"></script>
or
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")"></script>
It will solve your problems.
anAgent's answer helped me fix this problem, but as an add-on I will mention that, in my case, the multiple references to "jquery.unobtrusive-ajax.js" were in different files; one was in myView.cshtml, and the other was in _Layout.cshtml.
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.
just check this jquery reference
src="~/Scripts/jquery.unobtrusive-ajax.min.js"
may be you add in view twice or
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
精彩评论