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

How can I iterate through a collection on a template

2 Answers 1925 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 10 Feb 2020, 05:34 PM

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 Answers, 1 is accepted

Sort by
0
Simon
Top achievements
Rank 1
answered on 11 Feb 2020, 02:51 PM
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.
0
Tsvetomir
Telerik team
answered on 13 Feb 2020, 09:39 AM

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.
Tags
Grid
Asked by
Simon
Top achievements
Rank 1
Answers by
Simon
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or