6

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

1 Answer 1

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Stunning answer. This is something that I've been trying to figure out how to do for months.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.