ASP.NET MVC - Parent-Child Table Relation - how to creat Children in MVC (example request)
- by adudley
Hi All.
In a standard setup of Parent Child relation, lets say Project and Task. Where a Project is made up of lots of Tasks. So in a standard RDB, we have a
Project (ID, Name, Deadline)
Task (ID, FK_To_Project, Name, Description, isCompleted)
this is all very straight forward.
We have an MVC View that views Projects, so we get a nice list of all the project Names next to each deadline.
Now we want to CREATE a new PROJECT.
The Edit view opens, we type a name, say, 'Make a cup of Tea', with tomorrow as the deadline!
Still in this view/web page, I would like a list of all the Child Tasks, in a standard list, with Edit, Delete, and a Create/Add Task button too, just below the 'parent table' details.
The simplest way to describe this, is the Parents Table Create/Edit view, with the Childes List View Below it.
1) The ideal solution will also allow my Child Table (Tasks) to have Children also (for more complex scenarios) , and so on, and on, and on.
2) If I navigate away from my Created Project, I don’t want all sorts of random stuff laying around, they went away, it’s gone!
3) I’d expect all the same functionality when Editing an existing project.
I’m struggling with the ‘Add New Child’, I had a model dialog (jquery) and all was well, but now when editing an existing child/task, I need to populate the Child Edit, which is a pain and will need loads of java script I think :(
How can this be achieved in MVC, does anybody have any examples?