New to Telerik UI for ASP.NET Core? Download free 30-day trial

Using a Switch Case in Client Template

Environment

Product ListView for Progress® Telerik® UI for ASP.NET Core
Product Version 2019.1.220
ASP.NET Core Version 2.2

Description

I am just starting to utilize the list view for .net core. I have not determined if possible to dynamically set the template based upon a condition, I am trying to base the condition on a ViewBag property. I know the ViewBag value is available in the template because I can show its value in a div. However, I am not sure if it is possible to use in an if or switch condition, and if it is possible, what syntax I should use?

Solution

You can set the template dynamically with the help of the Kendo UI Template by adding conditions in the template or using functions:

    <script type="text/x-kendo-tmpl" id="template">
        # switch ("@ViewBag.SurveyType") {
            case "PolyGraph Examiner": #
            <div class="yellow">
                <h3>#= OrderID #</h3>
            </div>
            # break; #

            #case "B": #
            <div class="yellow">
                <h3>#= OrderID #</h3>
            </div>
            # break;} #
    </script>

More ASP.NET Core Resources

See Also

In this article