CheckboxFor sometimes show label, sometimes not

2 posts, 0 answers
  1. Henrik
    Henrik avatar
    11 posts
    Member since:
    Nov 2015

    Posted 01 Feb Link to this post

    Hi,

    I am using Telerik ASP.NET MVC Extensions 2016.1.111.0. and Razor. The CheckBoxFor control behaves slightly illogical - in one case it shows a label, in another case it does not. See the attached screenshot.

    Both parameters are booleans, the difference is that one of the has a DisplayName:

     

    From the model.cs

            public bool Dator { get; set; }
            [DisplayName("Passerkort 07:30-17:00")]
            public bool Passerkort { get; set; }

     

    From the Index.cshtml

                @Html.LabelFor(m => m.Dator)
                @Html.Kendo().CheckBoxFor(m => m.Dator)
                @Html.LabelFor(m => m.Passerkort)
                @Html.Kendo().CheckBoxFor(m => m.Passerkort)

    The parameter with the DisplayName specified will be displayed with a label attached to the CheckBoxFor, so to get rid of it I have to set .Label("") for that checkbox. Not a big deal, but I think maybe this was not the intention.

    Best regards,

    Henrik

     

  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1492 posts

    Posted 03 Feb Link to this post

    Hello Henrik,

    Thank you for contacting us.

    This is an expected behavior - when a data annotation attribute is set for a model field used inside CheckBoxFor() a corresponding label element is created. I would suggest that you either use other model field that doesn't have an attribute or remove the additional label.

    Regards,
    Danail Vasilev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top