Brian David Berman
Brian David Berman

Reputation: 7694

Access model data in ClientRowTemplate (Telerik MVC Grid control)

I am using the Telerik MVC Grid control...

I understand you can use the <#= SomeData #> syntax when you wish to stamp your data as a string within the ClientRowTemplate but what if you want to do server-side logic on some of your data in your ClientRowTemplate? How could you achieve this?

I have a bool, called CanDelete, in my model that I want to check and if it's true, show a DeleteButton. The code I have currently looks something like this:

.ClientRowTemplate(grid => "<div><#= SomeField #> " + grid.DeleteButton(null, GridButtonType.Image) + "</div>")

This works fine if I want to show the DeleteButotn every time but I want to check another field in my model first to determine whether to show it or not. Is this possible?

Upvotes: 2

Views: 1370

Answers (1)

Daniel
Daniel

Reputation: 5732

I don't know if it is the best way, but you can put conditional logic in your template.

.ClientRowTemplate(grid => "<# if(CanDelete) { #><div><#= SomeField #> " + grid.DeleteButton(null, GridButtonType.Image) + "</div><# } #>")

What you put in the conditional is limited. I have been able to do this successfully with a bool and an int comparison, but not with a string comparison.

Upvotes: 1

Related Questions