Problems with displaying values in dropdown customized template in scheduler appointment template

3 posts, 1 answers
  1. Jonas
    Jonas avatar
    42 posts
    Member since:
    Oct 2014

    Posted 07 Dec 2016 Link to this post

    Hello

    I'm using a kendo dropdownlistfor() inside a scheduler edit template, if I use just the basic dropdown everything works as expected, but if I try to use the templates for the dropdown all I get is undefined when I click to see the options of the dropdown. If I use the same dropdown directly on the page instead of in a template everything works ok with the dropdown template. Why are they not displaying correct in the scheduler edit template.

    So the problem is not with the datasource, I get all values from the db, and the code should be fine since it works directly on the page. I guess the only thing wrong with then code is "data.name" when used inside a template since this gives the undefined. What should it be when used inside a template?

    Code:

    @(Html.Kendo().DropDownListFor(model => model.equipmentId)
                        .HtmlAttributes(new { style = "width: 240px", @class = "showOpsDiv" })
                        .DataTextField("name")
                        .DataValueField("id")
                        .OptionLabel("Välj Utrustning...")
                        .Value("-1")
                        .DataSource(source =>
                        {
                            source.Read(read =>
                            {
                                read.Action("GetEquipment", "Home");
                            })         
                        .ServerFiltering(true);
                        })
                       .Template("<span class=\"k-state-default\"></span><span class=\"k-state-default\"><h3>#= data.name #</h3></span>")
                       .HtmlAttributes(new { data_value_primitive = "true" })
                     )     
  2. Answer
    Peter Milchev
    Admin
    Peter Milchev avatar
    183 posts

    Posted 08 Dec 2016 Link to this post

    Hello Jonas,

    If a template includes a # character, which is part of a binding expression of a nested template, then this character must be escaped as well. In this way the character is ignored by the outer template, but is handled correctly by the inner template. More information could be found in the Kendo Templates Overview article.

    Would you please check if escaping the hash literals in your DropDownList template solves the issue?

    Regards,
    Peter Milchev
    Telerik by Progress
    Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
  3. Jonas
    Jonas avatar
    42 posts
    Member since:
    Oct 2014

    Posted 08 Dec 2016 Link to this post

    Hello Peter

    That did the trick! :-)

    Thank you!

    /Jonas

Back to Top