【问题标题】:Kendo UI grid ClientTemplate ternary conditionKendo UI 网格 ClientTemplate 三元条件
【发布时间】:2021-06-23 10:58:46
【问题描述】:

我正在尝试在 Kendo UI 的 ClientTemplate 方法中添加条件。 If else 语句工作正常,但尝试使用三元运算符时 HTMl 不呈现。

工作代码:

@(Html.Kendo().Grid(Model)
        .Name("marketWatchGrid")
        .Columns(columns =>
        {
            columns.Bound(p => p.direction).ClientTemplate("# if(Clients==''){ # - #}else{# #: Clients # #}#")
        })
    );

不工作:

@(Html.Kendo().Grid(Model)
        .Name("marketWatchGrid")
        .Columns(columns =>
        {
            columns.Bound(p => p.direction).ClientTemplate("# Clients=='' ? '-' : #: Clients # #")
        })
    );

使用 htmlEncode

@(Html.Kendo().Grid(Model)
        .Name("marketWatchGrid")
        .Columns(columns =>
        {
            columns.Bound(p => p.Clients).ClientTemplate("# (Clients=='' ? '-' : kendo.htmlEncode(Clients) ) #")
        })
    );

【问题讨论】:

    标签: asp.net-mvc kendo-ui


    【解决方案1】:

    使用三元运算符的解决方案:

    @(Html.Kendo().Grid(Model)
            .Name("marketWatchGrid")
            .Columns(columns =>
            {
                columns.Bound(p => p.Clients).ClientTemplate("#: Clients=='' ? '-' : Clients #")
            })
        );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-06
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多