【问题标题】:MVC Telerik Grid Conditional column Value?MVC Telerik Grid 条件列值?
【发布时间】:2011-12-07 10:35:22
【问题描述】:

如何在 MVC Telerik Grid Control 中完成这项工作

 columns.Template(e => 
            { 
                        if (e.EndDate>DateTime.Now ) 
                        {
                         @Html.ActionLink("Stop", "StopMedication", "Medication", 
                             new { id = e.PrescriptionID }, new { @class = "standard button" })
                        } 
                        else {
                            @Html.ActionLink("Renew", "RenewMedication", "Medication",
                                new { id = e.PrescriptionID }, new { @class = "standard button" })
                             }
          });

【问题讨论】:

    标签: grid telerik conditional


    【解决方案1】:

    以下 sn-p 在 Telerik Grid 模板列中使用 Razor 语法应该可以正常工作:

                    columns.Template(
                        @<text>
                        @if (@item.EndDate > DateTime.Now) 
                        {
                         @Html.ActionLink("Stop", "StopMedication", "Medication", 
                             new { id = @item.PrescriptionID }, new { @class = "standard button" })
                        } 
                        else
                        {
                            @Html.ActionLink("Renew", "RenewMedication", "Medication",
                                new { id = @item.PrescriptionID }, new { @class = "standard button" })
                        }
                        </text>
                );
    

    利用模板内部的@&lt;text&gt;&lt;/text&gt;,以及使用代表当前项目(绑定到行的实体)及其属性的@item 对象,将允许您启动并运行此模板.

    【讨论】:

    • 惊人的答案。这是我几个月来一直试图弄清楚的事情。
    猜你喜欢
    • 1970-01-01
    • 2011-02-17
    • 2011-10-28
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多