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

build partial view within treelist template

3 Answers 121 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
elke
Top achievements
Rank 1
elke asked on 08 Feb 2017, 08:46 AM

Hi,

I'm trying to display a partial view in a treelist column 

This is the colum definition:

columns.Add().Field(e => e.PageID)
                .TemplateId("translation-template")                 
                .HtmlAttributes(new { @class = "center col-lg-2" });

 

In this codesnippit, the PageID in the first div is displayed correctly for each row in my treelist.

Now I want to use the #: PageID # to be pass into the Html.RenderAction as a parameter (instead of 4)

<script id="translation-template" type="text/x-kendo-template">
        <div>#: PageID #</div>
        <div>
            @{Html.RenderAction("_TranslationTemplate",
                         "Pages",
                          new { PageID = 4 });
                }
        </div>
    </script>

 

Thank you!

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 10 Feb 2017, 06:42 AM

Hello,

Have you tried to use the template hash syntax in the Html.RenderAction method? For example the code to look like: 

<script id="translation-template" type="text/x-kendo-template">
        <div>#: PageID #</div>
        <div>
            @{Html.RenderAction("_TranslationTemplate",
                         "Pages",
                          new { PageID = #= PageID# });
                }
        </div>
    </script>

You can also refer to the How to Use Action Links? article for more information about different templates based on whether it is server bound or ajax bound TreeList. 

Regards,
Boyan Dimitrov
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 visualization (charts) and form elements.
0
elke
Top achievements
Rank 1
answered on 10 Feb 2017, 09:38 AM

Hello ,

I had tried that hash before but I'm getting syntax errors (see screenshot)

Kind regards

Elke

0
Boyan Dimitrov
Telerik team
answered on 10 Feb 2017, 02:12 PM

Hello Elke,

For some reason when I pasted the code in the editor the quotes around the template expression disappeared. 

PageID = "#= PageID#"

Most probably this should  clean the errors in the visual studio, but it will not send the expected value (PageID to the action method). It is the same reason that I already explained in your other thread. The code will be executed on the server and this is client-side expression. My suggestion here is to include the JavaScript logic or template evaluation logic in the template directly. Please take a look at my reply in the other thread and let us know if you have any questions. 

Regards,
Boyan Dimitrov
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 visualization (charts) and form elements.
Tags
TreeList
Asked by
elke
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
elke
Top achievements
Rank 1
Share this question
or