tags:

views:

305

answers:

2

I have a specific controller action that is being called twice, which aside from being weird is causing problems with a singleton portion of my application (not really a problem, it just brought the double call to my attention).

Any idea why a controller action would be executed twice every time?

+7  A: 

Not returning false from a javascript click handler on a link that makes the call via AJAX. In this case, it will also take the default action of the link (i.e., a non-AJAX post to the same URL).

Ex.

<%= Html.ActionLink( "action", "controller" ) %>


$(function() {
   $('a').click( function() {
      var href = $(this).attr('href');
      $.get( href, function() { ... } );
      // needs "return false;" here to prevent double request
   });
}):
tvanfosson
Ah, that is a possible one. Looking into it...
Dusda
That was it! Thank you :).
Dusda
This was very helpful to my problem. I had an Action that was triggered twice.
Tx3
A: 

I face the similar problem, I tried with the solution given - but it did not work in my case.

AP
Now I have found that my application had AJAXToolKit controls and ToolKitScriptManager as script manager to the application. When ToolKitScriptManager replaced with ScriptManager the problem got resolved.
AP