Implode and Explode error on conversion from select2 multiple post
Implode and Explode error on conversion from select2 multiple post

I'm attempting to update using select2 multiple true option to post multiple values to the db but im running into conversion issues with the built ins. My option might be to convert the collection to a string using some lamda but i figured the built ins would work anyone else ran into this issue?
Form Data from datatables
data[1][RequestLine][SubstituteProducts][]
0:+2012
1:+1991
var response = new Editor(db, "RequestLine")
.Field(new Field("RequestLine.Id").Set(false))
.Model<RequestLineModel>("RequestLine")
.Field(new Field("SubstituteProducts")
.GetFormatter(Format.Explode())
.SetFormatter(Format.Implode())
)
;
SubstituteProducts within the db is of type varchar and the model within aspx I declare it as a string
error
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' to type 'System.String[]'.
This question has an accepted answers - jump to answer
Answers
Easiest option is probably to use the
separator
option the Select2 plug-in for Editor has. Then it is all done client-side and no need to use formatters on the server-side.Allan
Not sure how that would change the data type that is posted to the server. Are the implode and explode methods not suitable for collections?
Even after setting the separator /tokenSeparator to true the result is still posted as a array.
js
Add
separator: '|'
in your field configuration (not inside theopts
object). That will do the split / join on the client-side for you.Allan
Thank You Allan,
It seems that did the trick for posting to the server, but it does not like the name. I was required to do the below.
FROM
name: "RequestLine.SubstituteProducts"
TO
name: "RequestLine.SubstituteProducts[]"
ALSO
NEW LABEL w/ reassignments
Interesting - thank you. We'll take a look at the server-side aspect of this as well as that should work...
Allan