I have a class, MyModel, with over 100 properties (I know) that are all of bool? data type. I'm trying to dynamically generate two radio buttons (Yes / No) for each property instead of manually creating the controls for each. I'm able to achieve some of my desired output, but not bind the data with validation. The edit-form uses either a model or an edit context, I've tried both. (using syncfusion DataForm component)
First I tried just looping of the reflected property info.
@foreach (var prop in properties){<label>@prop.name</label><radio button value=true @bind-checked=@prop.SetValue(MyModel)><radio button value=false @bind-checked=@prop.SetValue(MyModel)>}Next I tried using a dictionary to store the field name and bool value, but dictionaries are read-only in this context and cannot be two-way binded.
var dict = new Dictionary<PropertyInfo, bool?>;(reflection here to set dictionary, setting bool? to null) @foreach (var kvp in dict){<label>@kvp.Key.Name</label><radio button value=true @bind-checked=@kvp.value><radio button value=false @bind-checked=@kvp.value>}Then I changed the dictionary to include a 'wrapper' object so the value can be changed. This works except then I cant use the edit context/ model for validation.
var dict = new Dictionary<PropertyInfo, BoolWrapper?>;@foreach (var kvp in dict){<label>@kvp.Key.Name</label><radio button value=true @bind-checked=@kvp.value.YesNo><radio button value=false @bind-checked=@kvp.value.YesNo>}public class BoolWrapper{public bool? YesNo {get; set;}}I'm open to any ideas on how to make this possible. I considered making the model class indexable, but I'm still pretty new to C# and it adds a lot of complexity that I can't quite understand.
Any ideas on how to make this possible is greatly appreciated.