0

So, i have a partial view, let-s say:

@model myModel
@{
Layout = null;
}

....
Html.BeginForm("action", "Controller", FormMethodPost)
..... 
.....
.....
.....
<input type="submit" value = "Go"/>
}

Inside of this partial view I am rendering a second partial view so this will be:

@model myModel
@{
Layout = null;
}

....
Html.BeginForm("action", "Controller", FormMethodPost)
..... 
@{Html.RenderPartial("secondPartial");}
.....
.....
<input type="submit" value = "Go"/>
}

the second partial also submits a form but this time with Ajax like so:

@model myModel
@{
Layout = null;
}

....
Ajax.BeginForm("secondAction", "sameController", new AjaxOption { HttpMethod = "POST", InsertionMode=InsertionMode.Replace, UpdateTargetID = "thisPartialDivId"})
..... 
.....
.....
.....
<input type="submit" value = "Go"/>
}

But now, everytime i submit the second partial it submits it's parrent with the rest of the fields null, even doe i specifically told it which action to submit to it just goes up to it's parent and submits that.

Any ideeas? thx :)

P.S. the reason for this: the second view submits a new value for a propperty and then it should add that value to a dropdown list in the parent view. The parent creates the object.

Kinda solved this with adding an AntiForgeryToken but then i got another error because i had 3 of those on that parent view (one on the parent and 1 on each partial). Still looking for a solution here. :)

tereško
  • 58,060
  • 25
  • 98
  • 150
Spluf
  • 810
  • 1
  • 11
  • 26

1 Answers1

0

It looks like you are nesting these forms. That will not work. See this question on the topic of nesting. My understanding of the specification is that your second form declaration will be ignored. This is in-line with your results as well.

It's tough to offer an alternative with so little understanding of your actual goal. However, it seems to me that there is no reason to nest these forms when AJAX is involved. You should be able to move your AJAX form outside of your parent form's definition to get the desired behavior. You can still modify the elements from the "parent" form when the AJAX returns.

Community
  • 1
  • 1
Kevin Burdett
  • 2,892
  • 1
  • 12
  • 19