I am creating a .Net web service to receive and process serialized form data from JQuery.form.js which has a couple of multiselects contained within the form.
The serialized data sent to the webservice includes content like this:
&travelwith=4&travelwith=5&travelwith=6
for the field ‘travelwith’ showing that a multi-selection of 3 items out of 10 available in the form’s select field.
Can I construct a strong typed class with the following for instance:
public class StoreUserSet
{
public Array travelwith { get; set; }
public string otherfield { get; set; }
....
}
and then have my web method take the object like this:
StoreUserSet StUserSet = new StoreUserSet(); // Create new class instance.
[WebMethod()]
public bool ProfSet1(StoreUserSet StUserSet)
{
...
}
Would the various values of the multiselect field ‘travelwith’ automatically be parsed into the Array travelwith of the class so that I can save the 3 item values as a comma separated list into SQL via LINQ ?
I haven’t got this far yet.. thought I’d get feedback on my planned approach.
Thanks for any feedback,
Martin.
ok, seeing as my KeyLargo site’s JQuery form contained both single select form data and multiple selects, I needed to be able to store the multiple selects in a single field within Sql.
I ran into problems trying to handle the multiple selects on the server using Array type for storing the data in a Sql single field with a comma delimited string. So the way I solved my question above was to create the strongly typed class with string[] to capture the serialized multi select data passed via AJAX to the server:
I used Rick Strahl’s handy method to handle multiselect array data being passed from the client:
To iterate through the array setting values like this:
Then joined the values in the multi select string[] arrays like this:
Easily enabling me to save the data into the relevant table fields of the profile.