views:

226

answers:

2

Hello!

i have view which looks something like this :

<% using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "someDiv", HttpMethod = "Post"))
   {%>

 <%= Ajax.ActionLink("Add new", "AddNewItem", new AjaxOptions { UpdateTargetId = "divAddNewItem", HttpMethod = "Get" })%>

<div id="divAddNewItem">
</div>

  <input type="submit" value="Create" />

<% } %>

"AddNewItem" action returns partial view, which is rendered to divAddNewItem, AddNewItem view code looks like this one :

<% using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "divAddNewItem", HttpMethod = "Post"))
   {%>

       <input type="submit" value="Add" />
<% } %>

in this case, after clicking "Add new" button IE will give exception (unknown runtime error), while chrome and firefox will work. i made some research, and it seems like nested form tags causing the problem.

would be glad to hear any possible hint or advice in solving this problem.

Thank You !

+2  A: 

Nested forms are illegal in HTML. You can't do it. IE tends to react worse than Firefox, but you should not do it in either browser.

There can be several forms in a single document, but the FORM element can't be nested.

Craig Stuntz
so, one of possible solutions would be to delete nested form , and replace submit button with Ajax.ActionLink ?
vbobruisk
Or just un-nest the form. You can have *multiple* forms; they just can't be nested.
Craig Stuntz
Hi. thanks for reply. If i'll un-nest them there will be some design issues :) . And if I use actionlink(or jquery), i'll need to pass all data to action manually ? (i.e. new { id=textbox1.value, name=textbox2.value } ?
vbobruisk
IMHO it is generally easier to un-nest forms than to bypass them completely. But it's your code, and I haven't seen it, so you'll have to decide that for yourself.
Craig Stuntz
+1  A: 

I prefer, in instances like this, to make a div which looks like a form (or even a dialog box a la DHTML) and wire up an ajax post of these "form" elements to an onclick event of the button. It's obviously a lot more work, but it's gotten me out of a lot of jams.

Anthony Potts