RadioGroup Issue not returning data back to controller.

1 Answer 63 Views
Grid RadioGroup
Shane
Top achievements
Rank 1
Shane asked on 07 Apr 2022, 02:34 PM

I have a grid doing edit  in a popup. When the popup shows it binds from my model to the fields  and all the fields bind and return their data back to the controller for Add/Update except for the RadioGroup it always returns null. It binds fine, just not returns any value to the Controller.

I tried the below:

@(Html.Kendo().RadioGroupFor(model => model.Sex)
                .Name("Sex1")
                .HtmlAttributes(new { style = "width:200px;", @class = "RequiredField" })
                .Layout(RadioGroupLayout.Horizontal)
                .Items(m =>
                {
                    m.Add().Label("Male").Value("Male");
                    m.Add().Label("Female").Value("Female");
                    m.Add().Label("N.A.").Value("N.A.");
                })           

)

I also tried using javascript to force it to update like below.

@(Html.Kendo().RadioGroupFor(model => model.Sex)
                .Name("Sex1")
                .HtmlAttributes(new { style = "width:200px;", @class = "RequiredField" })
                .Layout(RadioGroupLayout.Horizontal)
                .Items(m =>
                {
                    m.Add().Label("Male").Value("Male");
                    m.Add().Label("Female").Value("Female");
                    m.Add().Label("N.A.").Value("N.A.");
                })
                .Events(e =>
                {
                    e.Change("Sex_onChange");
                })

)

<script type="text/javascript">

function Sex_onChange(e) {
        var sexList = $("#Sex").data("kendoRadioGroup");
        sexList.trigger("change");
    }

</script>

 

No matter what I tried my model always returns null for the sex when it hits the controller.

 

Below is the model.

 public class ContactViewModel
{
        public Int32 ContactID { get; set; }
        [Required]
        [MaxLength(255)]
        [DisplayName("Display Name:")]
        public String DisplayName { get; set; }
        [Required]
        [MaxLength(10)]
        [DisplayName("Sex:")]
        public string Sex { get; set; }
}

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 12 Apr 2022, 12:56 PM

Hello Shane,

 

Thank you for writing to us.

The For part in RadioGroupFor() is not compatible with the   .Name("Sex1") property.

Can I ask you to remove the  .Name("Sex1") part and let me know if this resolves the issue?

 

Regards,
Eyup
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/.

Shane
Top achievements
Rank 1
commented on 12 Apr 2022, 12:58 PM

We already tried that changing it to "Sex" and it did not work. I accidentally put it in the forum with a 1 in the name.
Eyup
Telerik team
commented on 15 Apr 2022, 11:33 AM

Yeah, you can expect a full working MVC Grid project in the support thread later today.

I suggest that we continue our technical conversation there.

Sean
Top achievements
Rank 1
Iron
Iron
commented on 20 Feb 2023, 06:54 PM | edited

I had a similar issue where my RadioButtonGroup was not binding in a popup template. I also did not have that particular field as part of the columns in the grid.  After I mapped the field to the Model then the field started to bind in the popup properly.

 

Shane
Top achievements
Rank 1
commented on 20 Feb 2023, 07:04 PM

I also bound to a hidden field and on change of the radiobutton group in javascript, I also updated the hidden field and that caused it to post back for me. Just also make sure after binding to the hidden field you also tell it to trigger change ("$(#fieldname")..trigger("change");).
Eyup
Telerik team
commented on 23 Feb 2023, 03:31 PM

Hi


Tags
Grid RadioGroup
Asked by
Shane
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or