Error when clicking in a checkboxlist in popup when using Ajax

4 posts, 0 answers
  1. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 25 Apr 2013 Link to this post

    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
  2. Daniel
    Admin
    Daniel avatar
    2220 posts

    Posted 29 Apr 2013 Link to this post

    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!
  3. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 29 Apr 2013 Link to this post

    Hi,
    It's look like:
    public int[] SelectedRoles { get; set; }
    but I have also tested with:
    public IList<RoleTypes> SelectedRoles { get; set; }

  4. Daniel
    Admin
    Daniel avatar
    2220 posts

    Posted 01 May 2013 Link to this post

    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!
Back to Top