[Flags] Enum - MultiSelect Blazor component RRS feed

  • Question

  • User-1917609967 posted

    I'm am working on a blazor server-side webapplication which is basically about patients who can fill out several questionaires about their disease. This data is stored in a database via EF Core. My problem is that all questionaires feature a field, where the user can specifiy several options, a multiselect, with the underlying data type being a [Flags] Enum:

    public enum PainSite
        BehindBothEyes = 1,
        ... // 12 options in total 

    When using <InputSelect> I was only able to specify ONE option, since it does not allow the attribute "multiple". Binding one enum option did work but I need the input to be a multiselect! (no matter if dropdown or listbox). Thus I tried the following, which allows me to actually select multiple values but only one is actually bound and hence stored in the database. 

     <select multiple class="form-control" @bind="@PostOp.PainStart">
               @foreach (var painSite in Enum.GetValues(typeof(PainSite)))
                    <option value="@painSite">@painSite</option>

    Any idea? 

    Wednesday, April 8, 2020 6:21 AM

All replies

  • User389708749 posted

    This is two months old, so I assume you found the answer.

    Did you end up using a checkbox?

    Saturday, May 23, 2020 4:12 PM
  • User-1917609967 posted

    Unfortunately, I couldn't solve the problem regarding [Flags] Enum. I ended up creating an associated class with each SelectItem being a property of type bool and then I used a checkbox in my form. Works fine so far. 

    Friday, May 29, 2020 6:08 PM