MVC5, Creating a model which contains a list of objects

I'm new to MVC5 and am facing a problem with creating a Create View for a model which requires a list as an input.

I have a model called Parent which has a Name, Occupation, and an arbitrary number of Children represented by a List<Child> A Child can have a Name and an Age.

Without taking the list into account I have the following code which looks like it's working for the most part:

<div>Name: @Html.TextBoxFor(o => o.Name)</div> <div>Occupation: @Html.TextBoxFor(o => o.Occupation)</div> 

Except for the fact that the Children List is null and I have no idea what to do to Add Children. Should I be making a new view for CreateChild and somehow returning the new Child from that to this one? How would I do that? I'm a bit stumped.

For some context, I'm not using Entity Framework but instead have a repository object which talks to a dll in charge of dealing with the datastore.

by MacrosInHisSleep via /r/csharp

Leave a Reply