There was a javascript error on the page. Why this would cause the controller action to be invoked twice (or the request posted twice actually) is a mystery --- but somewhat irrelevnt for now.
Regards,
Eben
Marked as answer by ebenroux on Jun 10, 2008 08:08 AM
i've found this happen to me too a few times. i've found there's a tag in my page or ajax call referencing an empty URL, which browsers will interpret as the current page and request it again.
I haven't encountered it since preview 1 though, but my co-worker had this exact same problem that turned up because his ajax call had a URL of empty string.
I have also encountered this, and after a while pulling my hair out i discovered the source of the issue in my situation.
I was experiencing a situation where everything seemed to be running fine, but when entering debug mode and stepping through things went wiggy. When any page was requested, the controller action would fire, do everything it was supposed to, pass everything
on to the view which would then render all the HTML to the browser window, and the page would become usable... however Visual Studio would still be busy.
After debugger had stepped through all of the View code, it was then jumping to the same specific action in a controller, no matter what page had originally been requested. Obviously, this action expecting certain params then threw an error. This wasn't
discovered for a while however as the HTML had already been served and displayed in the browser before the second action was called.
The issue?
My page had an <img> tag referencing a .jpg file that no longer existed. Deleting the tag or supplying the source of an existing file solved the problem.
I'm not too knowledgable on browsers inner workings, but both IE and FF were producing the same result, so maybe upon realising that a resource wasn't downloaded the browsers retry with the same/similar request, hence the second call to the controller?
ebenroux
Member
2 Points
3 Posts
Controller action being called twice
Jun 10, 2008 06:24 AM|LINK
Hello all,
My controller action is being invoked twice.
I even tried entering the action on the url in case something was going wrong with click the link --- the action is still being called twice.
I have custom filter attributes applied to my controller --- I commented them out so its not them.
Any ideas?
Regards,
Eben
Paul Linton
Star
13403 Points
2531 Posts
Re: Controller action being called twice
Jun 10, 2008 07:05 AM|LINK
Can you post the code of the Controller and the view that is being rendered?
ebenroux
Member
2 Points
3 Posts
Re: Controller action being called twice
Jun 10, 2008 08:07 AM|LINK
Not to worry,
I have solved it --- kind of :)
There was a javascript error on the page. Why this would cause the controller action to be invoked twice (or the request posted twice actually) is a mystery --- but somewhat irrelevnt for now.
Regards,
Eben
CVertex
Member
147 Points
128 Posts
Re: Controller action being called twice
Jun 10, 2008 04:42 PM|LINK
i've found this happen to me too a few times. i've found there's a tag in my page or ajax call referencing an empty URL, which browsers will interpret as the current page and request it again.
I haven't encountered it since preview 1 though, but my co-worker had this exact same problem that turned up because his ajax call had a URL of empty string.
minusone
Member
5 Points
12 Posts
Re: Controller action being called twice
Apr 21, 2009 07:19 AM|LINK
I have also encountered this, and after a while pulling my hair out i discovered the source of the issue in my situation.
I was experiencing a situation where everything seemed to be running fine, but when entering debug mode and stepping through things went wiggy. When any page was requested, the controller action would fire, do everything it was supposed to, pass everything on to the view which would then render all the HTML to the browser window, and the page would become usable... however Visual Studio would still be busy.
After debugger had stepped through all of the View code, it was then jumping to the same specific action in a controller, no matter what page had originally been requested. Obviously, this action expecting certain params then threw an error. This wasn't discovered for a while however as the HTML had already been served and displayed in the browser before the second action was called.
The issue?
My page had an <img> tag referencing a .jpg file that no longer existed. Deleting the tag or supplying the source of an existing file solved the problem.
I'm not too knowledgable on browsers inner workings, but both IE and FF were producing the same result, so maybe upon realising that a resource wasn't downloaded the browsers retry with the same/similar request, hence the second call to the controller?
asp.net mvc controller action firing twice
bigbadmad
Member
4 Points
3 Posts
Re: Controller action being called twice
Feb 11, 2013 10:56 AM|LINK
It's worth pointing out for anyone using Firefox and Firebug for testing that Firebug will cause every Action to be called twice. Grrr