ASP.NET MVC - processing multiple objects in one form

I have a script I'm stuck on - I have a domain object that has a set of objects associated with it. Something like that:

public class Person
{
   public string Name { get; set; }
   public IList<PhoneNumber> PhoneNumbers {get; set; }
   public IList<Address> Addresses { get; set; }
}

The user interface that the client requires has one input form for adding and editing. The user can enter 0 for many phones / addresses for each person. How do I handle sending a collection of values ​​back to the controller?

I can come up with a couple of approaches, but they all seem brute force and not very elegant. Is there a best practice to solve this problem?

+5
source share
4 answers

.

<input name="Parent[childObjectType][serial_number]" type="textbox" value="" />

,

<input name="Person[PhoneNumber][1]" type="TextBox" value="555-1212" />
<input name="Person[PhoneNumber][2]" type="TextBox" value="555-555-1212" />

javascript, , formCollection , .

mvc ModelBinder . jquery javascript baulk.

0

json jQuery JSON.NET JsonFilter , json #. , . , , . .

http://blogger.forgottenskies.com/?p=252

0

In the mentioned Hanselman article, he writes that you do not need indexes, you have one name for the input fields and there is an array parameter in action, and it works.

0
source

All Articles