How to persist Model with List property

Topics: Customizing Orchard, Troubleshooting, Writing modules
Jan 4, 2013 at 8:43 AM

I've a part and I want it to have a list of strings as a property. Only I'm not to sure how to implement this in Orchard.

1) how to persist this in the database?  I don't know how many items will be in the list and you can't store the list items in different columns, therefore the list should be saved in one column and the items should be seperated with some kind of seperator. But how do you manage this with the ORM ?

2) The editor view is a challenge as well, will the IUpdateModel work if I dynamically add new html to add new items ? 

Thanks in advance!

Jan 5, 2013 at 12:00 PM

Bump.. 

Jan 5, 2013 at 3:54 PM

As far as mapping it with a record class...  I typically just serialize these sort of things into a a CSV, XML, or JSON string.  So, there is just a plain old string property in my record class that maps to a long text field in the database.  That part is pretty easy.  

You can then use your serialization mechanism to populate a collection in your custom part or in a view model.  Whatever makes sense for you.  

The editor view relies on asp.net model binders so if you want to submit form values to bind to a collection, you just have to follow the input naming conventions.  See Hanselman's blog for simple examples of collection model binding.