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?
MainListelements. In your view you will have a nestedforeachloop to work with theSublistelements. In the controller you just accept theMainListas a parameter (it should already have the sublists as members). Have you tried this approach? Is there something that doesn't work?nameattribute for your list elements and your sublist elements. That could give a clue why the ModelBinder is not picking them up. My guess is you are using partials and passing models into those partials, so the generated names include only the properties inside the sublist item, while it should contain the property of the main list first.