Following this post and the other posts that it links to, I have successfully built a page with a variable legnth editable list.
Now, I need to do another page with similar functionality, but going a step further. Basically I need to create a variable length list of objects as I have already done, but in this case each object in the list needs to have its own variable length editable sub list.
I can build the view with no problem but I guess I am lost as to how I will handle this in my POST controller method to save the objects.
Will my controller take 2 IEnumerable parameters?
I.E.
public ActionResult SaveList(IEnumerable<MainList>, IEnumerable<Sublist>)
{
}
It seems like this would work but I have no way of associatiing the objects in the sublist collection with the appropriate object in the main list collection.
What am I missing?
Summing up the results of our comment-discussions as an answer:
The sublists should be members of your
MainListelements. In the View you will have a nested foreach loop to work with theSublistelements. In the controller you just accept theMainListas a parameter (it should already have the sublists as members). In order for theModelBinderto pick up the sublists correctly, the names of the inputs should include the names of main list first (and not just the properties inside the sublist item).