Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action method being called multiple times

I've just spotted something quite strange about an action method that is being called, via a simple click of a link, in my MVC 3 site. For some reason this action method is being called multiple times. Not only that but subsequent calls get called before previous ones complete. What I mean is, suppose I have 10 lines of code in my action method, numbered 1, 2 ... 10. The first call of the method will execute lines 1,2 and 3. The second call executes lines 1,2,3 and 4, then the third call executes lines 1,2,3 and 4 and then the first continues from line 4 and so on. It's as if multiple threads are calling this action method, but as far as I can see nothing of the sort is happening because all I do to get this to happen is click on a link. Is there any reason why this should happen?

UPDATE

Actually, having done analysis, I can see that it is 2 calls that are being made.

like image 840
Sachin Kainth Avatar asked Oct 25 '12 14:10

Sachin Kainth


1 Answers

For anyone who is interested, here was the culprit

<div class="listing-holder" onclick="window.location='/Lot/Details/@auction.Id'">
   <a href="/Lot/Details/@auction.Id"><img src="@auctionLineModel.ImageUrl" alt="auction Image"/></a>
   ...
</div>

As you can see there is an onclick on the div and a href. Both were being called. Doh!

like image 136
Sachin Kainth Avatar answered Sep 25 '22 00:09

Sachin Kainth