build partial view within treelist template

4 posts, 0 answers
  1. elke
    elke avatar
    4 posts
    Member since:
    Jan 2017

    Posted 08 Feb Link to this post

    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!

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1911 posts

    Posted 10 Feb Link to this post

    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.
  3. elke
    elke avatar
    4 posts
    Member since:
    Jan 2017

    Posted 10 Feb in reply to Boyan Dimitrov Link to this post

    Hello ,

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

    Kind regards

    Elke

  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1911 posts

    Posted 10 Feb Link to this post

    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.
Back to Top