Note that there are some explanatory texts on larger screens.

plurals
  1. POmvc.net multiple forms childaction
    text
    copied!<p>I have 2 forms on a page, they are included in the masterpage like so:</p> <pre><code>Html.RenderAction("Form1", "Controller") </code></pre> <p>and</p> <pre><code>Html.RenderAction("Form2", "Controller") </code></pre> <p>The Controller has the following:</p> <pre><code>&lt;ChildActionOnly()&gt; Function Form1() As ActionResult Return View("Form1", New ModelObject()) End Function &lt;ChildActionOnly()&gt; &lt;AcceptVerbs(HttpVerbs.Post)&gt; Function Form1(ByVal formCollection As FormCollection) As ActionResult Return View("Form1", New ModelObject()) End Function &lt;ChildActionOnly()&gt; Function Form2() As ActionResult Return View("Form2", New ModelObject()) End Function &lt;ChildActionOnly()&gt; &lt;AcceptVerbs(HttpVerbs.Post)&gt; Function Form2(ByVal formCollection As FormCollection) As ActionResult Return View("Form2", New ModelObject()) End Function </code></pre> <p>The forms markup in the ascx is as follows, they are essentially the same form so the markup is very similar:</p> <pre><code>&lt;% Using Html.BeginForm()%&gt; &lt;%= Html.TextBoxFor(Function(model) model.Property1, New With {.class = "input"})%&gt; &lt;input type="submit" class="submitbutton" value="" name="submit" /&gt; &lt;% End Using%&gt; </code></pre> <p>The problem is, when I submit either form, it runs both post methods.</p> <p>So Form1 post and Form2 post, yet the values in the form collection are from which ever form was submitted.</p> <p>My question is: Why is this submitting both forms with one set of form data? How can I make it call only the relevant action with the correct form data?</p> <p>I am sure I am making a simple mistake, just cannot see it for looking.</p> <p>Project that demonstrates the problem can be found here: <a href="http://www.jimplode.co.uk/Content/TestMVC.zip" rel="nofollow">TestMVC.zip</a></p> <p>Thanks 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