HaBo
HaBo

Reputation: 14287

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

Upvotes: 6

Views: 4734

Answers (1)

carlbergenhem
carlbergenhem

Reputation: 1989

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.

Upvotes: 11

Related Questions