Implementing a multi select content field

Topics: Writing modules
Sep 23, 2011 at 7:18 PM

Hi,

Im writing my own content field for Orchard using this jQuery component http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/#basic

The problem is I don't know how to save data that gets posted and mapped back to the view model in the POST event of my XXFieldDriver.

This is the POST Editor function in my field driver:

 protected override DriverResult Editor(ContentPart part, Fields.MultiSelectField field, IUpdateModel updater, dynamic shapeHelper)
 {
 	var viewModel = new MultiSelectFieldVM();
        updater.TryUpdateModel(viewModel, GetPrefix(field, part), null, null);
	string selectedValues = viewModel.FieldValue; //this holds only one selected item
	return Editor(part, field, shapeHelper);
  }

When inspecting posted data with fiddler the selected item get posted like this: Region.countries3.FieldValue=AL&Region.countries3.FieldValue=DZ&multiselect_Region_countries3_FieldValue=AL&multiselect_Region_countries3_FieldValue=DZ

How can transfer all the selected items back to my view model?

Thanks!

 

Coordinator
Sep 23, 2011 at 7:24 PM

The system will do its best to map the incoming form to the object model you hand it. Model binders control this. If your object has properties named like the form fields, it should just work.

Sep 23, 2011 at 7:31 PM
Edited Sep 23, 2011 at 7:31 PM

Duuuuh I needed to declare an array field in my view model to save the selected items, thanks for the hint Bertrand!