Showing posts with label ASP.NET MVC HttpPost Html.RenderAction controller action. Show all posts
Showing posts with label ASP.NET MVC HttpPost Html.RenderAction controller action. Show all posts

Thursday, October 4, 2012

Issue Troubleshooting: "HttpPost action of a controller gets hit twice" while using @Html.RenderAction and JQuery

Following is the exact scenario in my application:

And this is an attempt to get assistance from various developers across in order to fix this issue.


I believe the issue is self-descriptive from the image above itself. Still if you have any question regarding understanding the issue, please feel free to post the same.
 
Thanks for visiting, and for your help

SOLUTION:

Having posted in StackOverflow and ASP.NET Forums, I got responses that helped me fixing the issue:

http://stackoverflow.com/questions/12722971/httppost-action-of-a-controller-gets-hit-twice

Following is the revised JQuery method, that worked:

            $('form').submit(function (event) {
                event.preventDefault();
                $.ajax({
                    url: 'EditEntryInline',
                    type: 'POST',
                    data: $(this).serialize(),
                    success: function (result) {
                        if (result.success) {                       
                            window.location.reload();
                        } else {
                            alert('Entry Could not be Saved');
                        }
                    }
                });
            });

The main issue was that, the event.preventDefault() was missing. 
Also, the suggestions were of not to wireup event for in button click event, though keeping above method inside $('.buttonInlineSave').click(function () { .... }) was also working pretty well.


Hope it helps someone.