Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC - RenderAction - PartialView - BeginForm() - multiple forms
    primarykey
    data
    text
    <p>So I have this ascx (partialView) control - ControlTemp</p> <p>I have an ajax.BeginForm inside ControlTemp like this:</p> <pre><code>&lt;% using (Ajax.BeginForm("ControlTemp", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divControlTemp" })) { .... &lt;input type = "submit" /&gt; &lt;%}%&gt; </code></pre> <p>Inside my masterpage, I am using this partialView as</p> <pre><code>&lt;div id = "divControlTemp"&gt; &lt;% Html.RenderAction("ControlTemp", "Home", null); %&gt;&lt;/div&gt; </code></pre> <p>Now the problem is if I have a page that is using this master page and the page does a postback to post, this function is also being fired:</p> <pre><code>[ActionName("ControlTemp"), AcceptVerbs(HttpVerbs.Post)] public ActionResult ControlTemp(string URL) { ... return PartialView("ControlTemp"); } </code></pre> <p>NOTE: Even if I use Html.BeginForm instead of Ajax.BeginForm, the above methods still ends up being triggered</p> <p>The page that is using this masterpage:</p> <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %&gt; &lt;asp:Content ID="loginTitle" ContentPlaceHolderID="TitleContent" runat="server"&gt; Log On &lt;/asp:Content&gt; &lt;asp:Content ID="loginContent" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;h2&gt;Log On&lt;/h2&gt; &lt;p&gt; Please enter your username and password. &lt;%= Html.ActionLink("Register", "Register") %&gt; if you don't have an account. &lt;/p&gt; &lt;%= Html.ValidationSummary("Login was unsuccessful. Please correct the errors and try again.") %&gt; **&lt;% using (Html.BeginForm("LogOn", "Account")) { %&gt;** &lt;div&gt; &lt;fieldset&gt; &lt;legend&gt;Account Information&lt;/legend&gt; &lt;p&gt; &lt;label for="username"&gt;Username:&lt;/label&gt; &lt;%= Html.TextBox("username") %&gt; &lt;%= Html.ValidationMessage("username") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="password"&gt;Password:&lt;/label&gt; &lt;%= Html.Password("password") %&gt; &lt;%= Html.ValidationMessage("password") %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= Html.CheckBox("rememberMe") %&gt; &lt;label class="inline" for="rememberMe"&gt;Remember me?&lt;/label&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="submit" value="Log On" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;% } %&gt; </code></pre> <p></p> <p>See the <code>Html.BeginForm</code> in above code... The <code>LogOn</code> ActionMethod is being fired, but it is firing ActionMethod of this another form as well!</p> <p>Another person posted this problem, but s/he did not have a solution:</p> <p><a href="https://stackoverflow.com/questions/523695/post-method-called-on-mvc-usercontrols-as-well-as-their-parent-views">POST method called on MVC UserControls as well as their parent views</a></p> <p><strong>Note: There are no nested forms</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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