How can I iterate through a collection on a template

3 posts, 0 answers
  1. Simon
    Simon avatar
    9 posts
    Member since:
    Nov 2019

    Posted 10 Feb 2020 Link to this post

    I have a external popup tempate that is called from a button on the grid. 

    @model CIPHRChecks.Models.Order;
    <div class="k-content popup-content">
        <text><input data-bind="value: Service.Name" /></text>  

        @foreach (var item in Model.Service.ServiceAdditionalData)
        {
        <p>@item.DisplayName</p>
        }
    </div>

    When I run the page it fails to load the Kendo Grid and I get the jscript error "Unexpected "</body>" or end of file. All open elements should be closed before the end of the document." This happens with any reference to the Model.

    There is nothing wrong with the data provided to the grid. It has the collection I want to iterate through. The intellisense for Model.Service.ServiceAdditionalData all works.

    Am I not supposed to use 'Foreach with Kendo or reference the model in this way. Should I use some other method to iterate through the collection and reference the data.

     

     

  2. Simon
    Simon avatar
    9 posts
    Member since:
    Nov 2019

    Posted 11 Feb 2020 Link to this post

    Solved my problem. There is no iterator in the Kendo Template syntax. I have used a JavaScript for loop.  Please confirm if this is the correct way forward.
  3. Tsvetomir
    Admin
    Tsvetomir avatar
    789 posts

    Posted 13 Feb 2020 Link to this post

    Hi Simon,

    The PopUp edit template follows the convention that is set by Microsoft. Namely, include a cshtml file to the EditorTemplates folder of the project. Looping through all of the items in a model should happen with the C# syntax. It is important to point out that the Model of the edit page contains information only based on the C# model declaration.

    However, in case the logic is executed with the Kendo Templates, you should utilize a conventional JavaScript loop for the same, as you have already done. More information on the matter could be found in the following article:

    https://docs.telerik.com/kendo-ui/framework/templates/overview

     

    Regards,
    Tsvetomir
    Progress Telerik

    Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Back to Top