Best way to handle dynamic list of items from admin UI?

Topics: Customizing Orchard, General, Writing modules
Feb 21, 2012 at 10:53 PM

Say a part has a list of child "Interesting Facts" parts. I know how to create a N:N relationship between the two. 

What i'm looking for though is a more user friendly way of letting users enter these InterestingFacts. They should be able to go into the parent content item and then add an arbitrary list of interestingFacts, and then save the part and have all the InterestingFact items save into the InterestingFacts table, with a parent child relationship to the parent content item. 

Like I said, database wise and Model wise I know how to make a part have a list of other parts (following the N:N example from the docs). What I'm looking for is a little guidance on making the UI sleeker, so the user can create the child parts at the same time as editing the parent part. 

Feb 22, 2012 at 12:29 AM

I would build the UI as something like this:

- Summary for interesting fact #1 -- [Delete]

- Summary for interesting fact #2 -- [Delete]

- Summary for interesting fact #3 -- [Delete]

Form to create and add a new fact


Feb 22, 2012 at 1:07 AM

I should have been more specific. What you suggest is what I had in mind, but what I'm not sure of is how to handle the postback for dynamically added items? I have never done a form with dynamic elements in MVC. I'm not sure how/if the model binding will work. In the past I did this with WebForms I would just number the form elements as they were created on the client side and loop through the form collection on server side. 

Is there a best practice or pattern to doing this in MVC (or in Orchard)? 

Feb 22, 2012 at 1:09 AM

You can have a specific form for that part, that posts to a specific controller action, with a return url. Then, you can probably add some Ajax sweetness.

Feb 22, 2012 at 1:10 PM

OK that would make sense. I was trying to figure out a way to do it with the part drivers but I guess that's not going to happen right? 

Feb 22, 2012 at 3:20 PM
Edited Feb 22, 2012 at 8:27 PM

Found an article describing the part I didn't understand -- model binding to a collection of models.

Feb 22, 2012 at 4:57 PM

I would like to know how to do this. Adding it to the documentation or a blog post would be awesome!

Feb 22, 2012 at 8:26 PM

I'll post something when I get around to this. The feature on my project that requires this is a little in the future so I may not get to it until a couple weeks from now.