This is a migrated thread and some comments may be shown as answers.

RadioGroup bind to Nullable<bool>

3 Answers 622 Views
RadioGroup
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Michael asked on 29 Jan 2021, 02:14 PM
Is it possible to use the new RadioGroup control with a Nullable<bool> model property.  It appears the RadioGroupFor expects a string bound property but not sure if there is way to work around that and have it bindable to a Nullable<bool>.

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 02 Feb 2021, 12:31 PM

Hello, Michael,

A possible workaround would be to set True and False as string options for the RadioGroup, and cast them to bool on the server. If the checkboxes were not selected/unselected before submitting, the value should be sent as null.

I hope that will be acceptable to you. Let me know if you have further questions.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Michael
Top achievements
Rank 2
Iron
Iron
Iron
answered on 02 Feb 2021, 12:46 PM

Martin,

While that would be a potential solution it makes it a workaround because I cannot model bind the control to a nullable bool - e.g. RadioGroupFor(Model.NullableBooleanField) and have it automagically handle everything for me.  I'm not averse to having to manually handle a single control but it does make it a challenge when all other kendo controls on the view are model bound and this one is not.  If I'm missing something here and it can be done please let me know.

Regards,

Michael

0
Martin
Telerik team
answered on 04 Feb 2021, 09:28 AM

Hello, Michael,

Unfortunately initializing the component for a string is the only way to bind it to a Model. And the suggested approach to convert to bool on the server is indeed a workaround, as the requirement is not supported out-of-the-box. On this Stackoverflow thread you can find ideas how to convert string to bool on the server. I hope it will be helpful.  

Let me know if you have any further questions.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
RadioGroup
Asked by
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Martin
Telerik team
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or