RadioButtonFor with boolean

Hi,

Using standard MVC libraries I can use:

@Html.RadioButtonFor(m => m.IsActive, "true")
@Html.RadioButtonFor(m => m.IsActive, "false")

where:

IsActive is a bool

To create a radio button that toggles IsActive between true and false.

However when I try to do this with EJ

@Html.EJ().RadioButtonFor(m => m.IsActive, "true")
@Html.EJ().RadioButtonFor(m => m.IsActive, "false")

I get the exception:

Cannot convert System.Boolean to System.String.

I have also tried:

@Html.EJ().RadioButtonFor(m => m.IsActive, true)
@Html.EJ().RadioButtonFor(m => m.IsActive, false)

But I get the same result

I cannot find the correct usage of this control in your documentation, so I am wondering how to correctly create a control like this.

Thanks

8 Replies

MK Muthukrishnan Kandasamy Syncfusion Team March 9, 2020 09:58 AM UTC

Hi Campbell, 
 
Thanks for using Syncfusion controls. 
 
We have checked your query in Radio Button control. we suspect that you have defined IsActive datatype as Boolean in models file. EJ Radio button value was string type so that issue was arises in your case. To resolve your problem, please change the IsActive datatype as string. Please refer to the below code block. 
 
[HomeController.cs] 
 
    
RadioModel model = new RadioModel(); 
   public ActionResult Index() 
        { 
            model.IsActive = "true"; 
            return View(model); 
        } 
 
 
 
  public class RadioModel 
    { 
        public string IsActive { get; set; } 
    } 
 
 
[Index.cshtml] 
 
    @Html.EJ().RadioButtonFor(m => m.IsActive, "true") 
    <label for="Radio1" class="clslab">True</label> 
 
    @Html.EJ().RadioButtonFor(m => m.IsActive, "false") 
    <label for="Radio2" class="clslab">False</label> 
 
 
We have prepared sample for your convenience, please refer to the below link for the sample. 
 
 
 
Please let us know, if you need any assistance. 
 
Regards, 
Muthukrishnan K 



CW Campbell Wray March 9, 2020 12:58 PM UTC

Thanks Muthukrishnan,

So by your example there is no way to do this with a Boolean instead of a string?

If so then I will just use the standard EJ radiobutton and parse it myself, as the datatype of IsActive needs to remain as a bool.

Is there a way to submit a change request to get this functionality added? It is already possible using standard MVC controls so it would make sense to have it in EJ too

Campbell


MK Muthukrishnan Kandasamy Syncfusion Team March 10, 2020 09:24 AM UTC

Hi Campbell, 
 
Thanks for the update. 
 
We have considered to include your expected feature requirement in EJ RadioButton control. The support for this feature will included in the NuGet release in the fourth week of March 2020.   
 
We appreciate your patience until then. 
 
Regards, 
Muthukrishnan K 



MK Meisam Kisomy May 12, 2020 05:39 PM UTC

Hi there,
This is what I need, has the change happened?

BR,
Meisam


MK Muthukrishnan Kandasamy Syncfusion Team May 13, 2020 05:28 AM UTC

Hi Meisam, 
 
Thanks for contacting Syncfusion support. 
 
We have fixed this issue and included fix in this version (18.1.0.42). We can use any version after this release. We can also use latest version of Syncfusion.Aspnet.Mvc5 NuGet to resolve this issue. We have prepared sample for your convenience, please refer to the below link for the sample. 
 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Muthukrishnan K 



LH LE Hoan Thieu Vu replied to Muthukrishnan Kandasamy July 16, 2020 08:26 AM UTC

Hi Meisam, 
 
Thanks for contacting Syncfusion support. 
 
We have fixed this issue and included fix in this version (18.1.0.42). We can use any version after this release. We can also use latest version of Syncfusion.Aspnet.Mvc5 NuGet to resolve this issue. We have prepared sample for your convenience, please refer to the below link for the sample. 
 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Muthukrishnan K 


Hi, 
Could you confirm the update only for EJ version? How about EJ2, because I'm still facing the issue in EJ2 with version 18.1.0.42.


MV Madhan Venkateshan Syncfusion Team July 30, 2020 02:05 PM UTC

Hi LE Hoan Thieu Vu, 
 
Good day to you. 
 
Currently, Boolean type support for RadioButtonFor is not available, we have logged this as improvement which will be available in Volume 3 2020 release and appreciate your patience until then. You can track the same through the below feedback link. 
 
 
Regards, 
Madhan V 



GK Gayathri KarunaiAnandam Syncfusion Team July 4, 2021 05:14 AM UTC

Hi LE Hoan Thieu Vu, 

We are glad to announce that our Essential Studio 2021 Volume 2 Main release v19.2.0.44 is rolled out and is available for download under the following link. We have provided the support [Boolean support for RadioButton] in this release. Please upgrade your project by using the below link. 


We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 

Please check the below code snippet and sample. 

<h4 class="row">Select the Gender</h4> 
            <div class="row"> 
                @Html.EJS().RadioButtonFor(model => model.gender, true).Label("Male").Render() 
            </div> 
            <div class="row"> 
                @Html.EJS().RadioButtonFor(model => model.gender, false).Label("Female").Render() 
            </div> 
 
public ActionResult Index() 
        { 
            RadioButtonModel model = new RadioButtonModel(); 
            model.gender = false; 
            return View(model); 
        } 
public class RadioButtonModel 
    { 
        public bool gender { get; set; } 
    } 
 


Regards, 
Gayathri K 


Loader.
Up arrow icon