I have a specific controller action that is being called twice, which aside from being weird is causing problems with a singleton portion of my application (not really a problem, it just brought the double call to my attention).
Any idea why a controller action would be executed twice every time?
There are 7 types of content returning results: ViewResult. PartialViewResult. ContentResult.
MVC action methods are strictly invoked via HTTP (Hypertext Transfer Protocol). In the URL, it should not be any duplicate value of address or name.
ASP.NET MVC Action Methods are responsible to execute requests and generate responses to it. By default, it generates a response in the form of ActionResult. Actions typically have a one-to-one mapping with user interactions.
Not returning false
or preventing the default action on the event in a JavaScript click handler on a link that makes the call via AJAX. In this case, it will also take the default action of the link (i.e., a non-AJAX post to the same URL).
Ex.
<%= Html.ActionLink( "action", "controller" ) %> $(function() { $('a').on('click', function(e) { // solve with "e.preventDefault();" here var href = $(this).attr('href'); $.get(href, function() { ... }); // or solve with "return false;" here to prevent double request }); }):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With