This project is read-only.

Associating 1-to-n relationship in driver

Topics: Customizing Orchard, Writing modules
Mar 17, 2011 at 9:17 PM

I have a collection that get rendered to a drop down list and on the post back I want to use the selected id from that drop down list to populate my n object from my 1-to-n model.

This works but I'm wondering if there a better way to do this?

      protected override DriverResult Editor(ContactFormPart part, Orchard.ContentManagement.IUpdateModel updater, dynamic shapeHelper)
         var contractListId = _orchardService.WorkContext.HttpContext.Request.Params["ContactList_Id"];
         bool success = updater.TryUpdateModel(part, Prefix, null, null);
         if (success && !string.IsNullOrEmpty(contractListId) && part.ContactList == null)
            part.ContactList = _contactListPartRepository.Get(int.Parse(contractListId));
         return Editor(part, shapeHelper);

Mar 18, 2011 at 8:29 PM

That's fine I think. I suppose you could have a model binder take care of that sort of thing, but it sounds horribly overkill.