MVC controller is being called twice

后端 未结 16 602
无人及你
无人及你 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:56

    Something very stupid I did...had 2 Forms on a page with one button on each form. I had added script to submit a specific form based on the button clicked but, since the default action of a button on a form is to do a submit, it called my Controller Action twice. :^(

        $('#SaveButton').click(function (event) {
            $("#AttendanceDetailForm").submit();
        });
    
    0 讨论(0)
  • 2020-11-27 05:58

    You can step through the code in your view. Step through and see where the second call comes from.

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

    Try changing the int? id to int id. It's matching the route the 2nd time because you're calling the index again with a null id.

    0 讨论(0)
  • I was chasing my problem and found it in here:

    Had <div style="width: 200px; height: 200px; background-image: url('\Asd\image.jpg')"></div> and problem made \ character so inside server side code i replaced all \ with / and it is working as charm.

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