views:

27

answers:

2

I have a page that collects information on two objects of the same type. When the page is submitted the action that handles the processing of the information submitted is attempting to use model binding, something similar to:

public ActionResult Submit(Person parent, Person child)
{
     //Do some stuff
}

It manages to bind one of them successfully but not the other. Does anyone have any suggestions/resources etc that could help me get this to work?

If needed I can gut/rename and post the actual code for the various pieces.

+1  A: 

Would it make sense to have a ParentChild Model with two person instances in it?

I don't think I've seen any examples like this trying to bind two models on post.

Simon Hazelton
This is one approach that I had considered, however, it seems like it should be possible to bind two separate objects of the same type.
mwright
+2  A: 

The solution to this is very much similar to the solution to my question that I posted the other day (I wouldn't at all call this a dupe though).

What you need to do is just include the parameter name in your inputs, eg:

<%: Html.TextBox("Parent.Name") %>
.....
<%: Html.TextBox("Child.Name") %>

and it should all automagically work.

(I think this is MVC2 only, you didn't mention whether you were using 1 or 2)

Jon
I'll try this out and see if I can make it work. I've updated the question tags to show that I'm using MVC 2.
mwright
Worked great, thanks!
mwright