This is a migrated thread and some comments may be shown as answers.

[Solved] pass bound data to custom function inside client template?

5 Answers 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jon Baron
Top achievements
Rank 1
Jon Baron asked on 18 Jul 2012, 08:03 PM
Hey all,

So I hope to do the above, similar to:

ClientTemplate("<br />"
                                + @Html.Label("<#= Name#>")
                                + "<br />")

But rather:

ClientTemplate("<br />"
                                + Model.Function("<#= Name #>")
                                + "<br />")

In the second example, I don't get my bound data in my method. Instead it's just "<#= Name #>"

In short, I'm trying to bind an IEnumerable property of my main IEnumerable that the grid is bound to, for a list of checkboxes in a column.

Thanks!

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 19 Jul 2012, 07:35 AM
Hello Jon, 

The client template is executed client-side. As a result you cannot call server-side code (such as Model.Function) in it. There are two options
  1. Switch to server binding and use a server template
  2. Convert the code from Model.Function to JavaSript:
    ClientTemplate("<br/> <#= myFunction(Name) #> <br/>")
    <script>
           function myFunction(name) {
                   return "<strong>" + name + "</strong>";
           }
    </script>

Regards,
Atanas Korchev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Jon Baron
Top achievements
Rank 1
answered on 19 Jul 2012, 12:22 PM
Thank you very much.

Can you please point out an example of the server side piece?

Thanks!
0
Atanas Korchev
Telerik team
answered on 19 Jul 2012, 12:33 PM
Hello Jon,

 Here is an example which is showing how to use server templates: http://demos.telerik.com/aspnet-mvc/grid/templatesserverside 

All the best,
Atanas Korchev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Jon Baron
Top achievements
Rank 1
answered on 19 Jul 2012, 01:23 PM
Great thanks!

Last question: How can a columns value be passed into an EditorTemplate?

Thanks!
0
Atanas Korchev
Telerik team
answered on 19 Jul 2012, 02:48 PM
Hello,

 It depends on the binding mode of your grid. Are you using server or ajax binding mode?

 In server binding mode the whole model is available in the editor template. Use the Model property.

 In ajax binding mode you need to use OnEdit event.

Regards,
Atanas Korchev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
Tags
Grid
Asked by
Jon Baron
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Jon Baron
Top achievements
Rank 1
Share this question
or