I am struggling to get the selected value of a list inside a Sitecore Forms 9.1 custom submit action.
The value I am seeing is:
System.Collections.Generic.List`1[System.String]
From the various samples on the Internet - I have tried using:
return field?.GetType().GetProperty("Value")?.GetValue(field, null)?.ToString() ?? string.Empty;
and
var postedField = (IValueField)viewModel;
IValueField valueField = postedField as IValueField;
PropertyInfo property = postedField.GetType().GetProperty("Value");
object postedValue = (object)property != null ? property.GetValue((object)postedField) : (object)null;
Which works fine for text values, but not for the selected radio button or checkbox from a list.
I could just check if the type is a list/collection and iterate over the values but just wanted to check if there was something cleaner already out there.