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

Error when clicking in a checkboxlist in popup when using Ajax

3 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mattias
Top achievements
Rank 1
Mattias asked on 25 Apr 2013, 10:03 AM
Hi,
I have a list of checkboxes, but when I click to check one all checkboxes is checked.
This is when using Ajax binding:
<input id="SelectedRoles_Administrators" type="checkbox" value="Administrators" name="SelectedRoles" data-bind="checked:SelectedRoles">
<label for="SelectedRoles_Administrators">Administratör</label>
   
<input id="SelectedRoles_SuperAdministrators" type="checkbox" value="SuperAdministrators" name="SelectedRoles" data-bind="checked:SelectedRoles">
<label for="SelectedRoles_SuperAdministrators">Superadministratör</label>
But when using Server binding it works as it should:
<input id="SelectedRoles_Administrators" type="checkbox" value="Administrators" name="SelectedRoles">
<label for="SelectedRoles_Administrators">Administratör</label>
    
<input id="SelectedRoles_SuperAdministrators" type="checkbox" value="SuperAdministrators" name="SelectedRoles">
<label for="SelectedRoles_SuperAdministrators">Superadministratör</label>
Is it some sort of a bug or is the code wrong typed in some way?
Original code:
@foreach (var role in roles)
 {
    <input type="checkbox" name="SelectedRoles" id="SelectedRoles_@(role.Enum)" value="@role.Enum"  /><label for="SelectedRoles_@(role.Enum)">@role.Text</label>
}
/Mattias

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 29 Apr 2013, 10:17 AM
Hello Mattias,

What  type is the "SelectedRoles" field in your model? When using a list of checkboxes it should be a collection. If it is not a collection then you could use radio buttons. Please check this documentation topic for information on checked binding.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mattias
Top achievements
Rank 1
answered on 29 Apr 2013, 12:43 PM
Hi,
It's look like:
public int[] SelectedRoles { get; set; }
but I have also tested with:
public IList<RoleTypes> SelectedRoles { get; set; }

0
Daniel
Telerik team
answered on 01 May 2013, 06:14 AM
Hello Mattias,

If the field is a collection then the problem could be cause the property not being initialized. Please check if initializing the collection in the ViewModel constructor resolves the problem:

public class MyViewModel
{
    public MyViewModel()
    {
        this.SelectedRoles = new List<RoleTypes>();
    }
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Mattias
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Mattias
Top achievements
Rank 1
Share this question
or