MVC Telerik网格有条件列值?

6
如何在MVC Telerik Grid控件中使此功能工作。
 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" })
                             }
          });
1个回答

11

以下代码片段应该可以在使用Razor语法的Telerik网格模板列中完美运行:

                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>
            );

使用模板中的@<text></text>以及使用代表当前项(与行相关联的实体)及其属性的@item对象,将使您能够启动并运行此模板。


1
惊人的答案。这是我几个月来一直在努力尝试解决的问题。 - Richard Harrison

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接