Note that there are some explanatory texts on larger screens.

plurals
  1. POView form calls on postback all controllers' actions with [HttpPost] from different controllers
    text
    copied!<p>I know that maybe the title sounds a bit weird but I believe that my problem is weird indeed. I have an ASP.NET MVC 4 application (this is my first MVC real-world application) with Razor view-engine. </p> <p>I have a layout view where I'm rendering two partial views like this:</p> <pre><code> &lt;!-- Login --&gt; @Html.Action("RenderLoginPopup", "Login") &lt;!-- Registration --&gt; @Html.Action("RenderRegisterPopup", "Login") </code></pre> <p>Each of those actions from the Login controller just renders a partial view:</p> <pre><code> [ChildActionOnly] public ActionResult RenderLoginPopup() { return PartialView("Partial/_LoginPopupPartial"); } </code></pre> <p>Just for exemplification sake (both are built the same way), the login partial view contains an ajax form like this:</p> <pre><code>@using (Ajax.BeginForm("Login", "Login", new AjaxOptions() { HttpMethod = "POST", OnSuccess = "loginResponseReceived" }, new { @id = "loginForm" })) </code></pre> <p>The Login action from the Login controller (the target of the form) is signed with the following attributes (worth to mention and notice the HttpPost one):</p> <pre><code> [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public JsonResult Login(LoginModel model) { } </code></pre> <p>So far, so good... Everything works perfect - both the login and the register actions are working without any issues.</p> <p>The issue that I want to speak about shows-up when I have a @Html.BeginForm() in a view that is loaded along with the main layout. For example, if I have a pure and simple form like this:</p> <pre><code> @using (Html.BeginForm()) { &lt;input type="hidden" name="name"/&gt; &lt;input type="submit" value="Send"/&gt; } </code></pre> <p>along with the controller CaptionExtendedController:</p> <pre><code> [HttpPost] public ActionResult Index(string nume) { return View(); } </code></pre> <p>So, in the end, in my final html generated file I will have 3 forms - 2 for login and register (ajax) and one simple form generated from the last view. Please keep in mind that all three forms are independent (meaning that they are not one in another). </p> <p>The issue is that everytime I'm pressing the button "Send" from the last form all controllers that are signed with the [HttpPost] attribute from my view (Login, Register from LoginController and Index from CaptionExtendedController) gets called.</p> <p>WHY??? In order to have a temporary fix, I've removed the [HttpPost] attribute from the Login and Register actions and now it's working but I don't think this is correct.</p> <p>Please, there is someone who can explain me why this is happening and eventually point me to the right direction in fixing this issue?</p> <p>Thank you in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload