title: Dynamically Generated Ajax.BeginForm
body: <p>I have a problem with ASP.NET MVC Ajax forms. I generate several Ajax forms in a table, like this:</p>
  
  <pre><code>&lt;% 
  foreach (var item in Model)
         {
             var statefulItem = item as StatefulEffectiveItem; %&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;% using (Ajax.BeginForm("ShowAddActivity", "EffectiveItems", new { id = item.Id }, new AjaxOptions() { UpdateTargetId = "details", OnSuccess = "dialogIt" }))
                 { %&gt;
              &lt;input type="submit" name="activity" value="Add Activity" /&gt;
              &lt;% } %&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;% } %&gt;
  </code></pre>
  
  <p>so far so good. When I post one of those forms, it renders a partial view in a div, and this new partial view contains a new Ajax.BeginForm (which is NOT nested in the originator form). This second Ajax.BeginForm is absolutely similar to the ones I generate in the table, but when I post it I don't get an "Ajax post", but a normal post which sends me to a new page. I don't understand what causes the difference between this two Ajax form, why this "dynamically generated" Ajax form behaves like a normal html form?</p>
  
  <p>By the way, I know I can do this in different ways using Javascript, but I would like to understand if this can be done just using MVC helpers and Ajax Library and, if the answer is "yes", where I do wrong.</p>
  
  <p>Thank you very much,</p>
  
  <p>Wasp</p>