MVC controller is being called twice

后端 未结 16 600
无人及你
无人及你 2020-11-27 05:15

I have a controller that is being called twice from an ActionLink call.

My home page has a link, that when clicked calls the Index method on the Play controller. An

相关标签:
16条回答
  • 2020-11-27 05:39

    I was also facing the same issue. after thoroughly checking my project , i found none such empty reference case. Then i found out that it is caused by FireBug. Disabling firebug or using other browser which has not firebug installed solved the problem.

    0 讨论(0)
  • 2020-11-27 05:40

    10 hours chasing that bug in a Java Spring Maven project.

    First on SELECT I thought Hibernate was just logging twice, but then with INSERT I thought requests were called twice. Stepping throught the code I discovered controller was called twice...

    Tried all possible Spring configuration, thinking the context was loaded twice or a bean was instantiate twice...

    In despair, rebuilded the project piece by piece to finally add a fragment of HTML and kaboom bug's back.

    <img alt="" src="#" />
    

    The sharp sign was guilty, reloading the URL. I know the topic is old, but I summarized my searchs with the words I used to look for in vain on Internet to find an answer to the same issue! Could help others...

    0 讨论(0)
  • 2020-11-27 05:41

    While debugging I found out that a Partial View causes the the Controller to be called a second time. It sucks, but I don't see a work around that one.

    0 讨论(0)
  • 2020-11-27 05:43

    I also had the same problem. my problem was because of an add-on I installed in the browser.

    Check out the add-ons in your browser.

    0 讨论(0)
  • 2020-11-27 05:46

    In my case, I was using a Partial View (so no Form tags) and using an on click handler in JQuery to call a method in the controller via Ajax. But I had declared the button the handler was attached to as type Submit. I forgot to pass in e to my handler function so as to call e.PreventDefault()!! So the Controller method was being called twice - once from an ajax call and once for Submit. The 2nd time around the parameters were null. This caused me so much grief. Such a small thing. So small that it was easily overlooked. Hope this helps someone else.

    0 讨论(0)
  • 2020-11-27 05:49

    In my case it was incorrectly configured remote script Yandex.metrika (Google analytics analog). This script was presented on each page, so any controller and any action was called twice. Check your Ya.metrika settings for more details.

    0 讨论(0)
提交回复
热议问题