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

Can't access model value in client template

2 Answers 288 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Veteran
Jay asked on 04 Apr 2017, 08:53 PM

So I have a grid with a ClientDetailTemplate, with both having client templates referring to item values. This works fine, basically something like

@(Html.Kendo().Grid(Model.Fields)
    .Name("FieldsGrid")
    .Columns(columns =>
    {
        columns.Bound(o => o.Title).Title("Title").Width("25%")
           .HeaderHtmlAttributes(new { Title = "Title", style = "text-align:center;" })
           .HtmlAttributes(new { Class = "lt" }).ClientTemplate(
            "<a target='_blank' href='#= Url #'>#= Title #</a>"
        );
    })
   .ClientDetailTemplateId("template")
 )
 
<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().Grid(Model.JobSearchResults)
        .Name("CareerJobSearchResultGrid_#=JobSearchId#")
        .Columns(columns =>
        {
            columns.Bound(o => o.Title).Title("Title").Width("40%")
              .HeaderHtmlAttributes(new { Title = "Title", style = "text-align:center;" })
              .HtmlAttributes(new { Class = "lt" }).ClientTemplate(
                "<a target='_blank' href='\\#= Url \\#'>\\#= Title \\#</a>"
            );           
        })
        .ToClientTemplate()
    )
</script>

 

The problem is when I want to add some HTML attributes based on some model information, trying to do something like 

.HtmlAttributes(new { Class = "lt", data_title = "#= Title #" })

I can't get this to work for either the grid or its client template, regardless of escapes etc.

Basically, it doesn't appear to do the substitutions, and in both cases, I get an error:

SyntaxError: missing : after property id
    ...tes:{Class:"lt",data-title:"#= Title #"},width:"10%",tem

 

Is what I'm trying to do possible and I'm just using the wrong syntax? Or is it not possible?

Thanks in advance.

 

2 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 06 Apr 2017, 10:34 AM
Hello Jay,

I was not able to reproduce the same issue on my end.

I made an example with a template for setting attributes and it is working as expected.

If additional assistance is needed, please send a fully runnable example and I will gladly assist. 

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Gabriel
Top achievements
Rank 1
answered on 26 Feb 2020, 02:39 PM
Life saver!!
Tags
Grid
Asked by
Jay
Top achievements
Rank 1
Veteran
Answers by
Stefan
Telerik team
Gabriel
Top achievements
Rank 1
Share this question
or