Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Telerik Grid Conditional column Value?

How can i get this work in 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" })
                             }
          });
like image 676
HaBo Avatar asked Oct 14 '11 03:10

HaBo


1 Answers

The following snippet should work perfectly fine in the Telerik Grid template column using Razor syntax:

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

Taking use of the @<text></text> inside of the template, as well as using the @item object, which represents the current item (entity tied to the row) and it's properties, will allow you to have this template up and running.

like image 175
carlbergenhem Avatar answered Sep 19 '22 14:09

carlbergenhem