ClientTemplate in Kendo UI invoke method from controller

1 Answer 36 Views
Grid
Deivydas
Top achievements
Rank 1
Deivydas asked on 23 Sep 2024, 06:52 AM

column.Bound(x => x.ReportUrl).ClientTemplate("<a href='#= ReportUrl #' target='_blank'>#= ReportUrl #</a>").Width(100);

Can I use a ClientTemplate to invoke a method from my controller when I click on the record in grid? 

Maybe there is some examples?

1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 25 Sep 2024, 01:58 PM

Hello Deivydas,

To access a server-side method when a specified Grid table cell is clicked, you need to trigger an AJAX request to the respective method. For example:

  • Handle the onclick event of the anchor tag and initiate a POST request to the server:
column.Bound(x => x.ReportUrl)
.ClientTemplate("<a href='javascript:;' onclick='report(\"#= ReportUrl #\");'>#= ReportUrl #</a>");

<script>
function report(reportUrl) {
 $.ajax({
    url: reportUrl,
    type: "POST",
    success: function() {
      ...
    }
  });
}
</script>

Let me know if this approach works for you.

 

Regards,
Mihaela
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Deivydas
Top achievements
Rank 1
Answers by
Mihaela
Telerik team
Share this question
or