ListView Template trying to add a partial View

4 posts, 0 answers
  1. Manoj
    Manoj avatar
    3 posts
    Member since:
    Apr 2011

    Posted 22 Dec 2012 Link to this post

    I am trying to use a Partial View as a Template for  the listView.  

    are there any exapmples?  

    The Template gives an error.

    If I try to create a Script is does not pass ITEM that is in a loop in the listview.  

    <script type="text/x-kendo-tmpl" id="template">
                <div class="item-box">
                    @Html.Partial("_ProductBox", item)
                </div>
    </script>



      @(Html.Kendo().ListView<ProductOverviewModel>(Model.Products)
        .Name("listView")
        .TagName("div")
        .ClientTemplate(@<text><div class="item-box">
                    @Html.Partial("_ProductBox", item)
                </div></text>))
        //.ClientTemplateId("template")
        .DataSource(dataSource => {
        dataSource.Read(read => read.Action("HomepageProducts", "Catalog"));
            dataSource.PageSize(12);
            
        })
        .Pageable()        
    )
            
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 25 Dec 2012 Link to this post

    Hello,

    ClientTemplate value is string after all - you do not need such @<text></text> tags. 

    I suggest you to also look at this topic from the documentation. 

    http://docs.kendoui.com/howto/load-templates-external-files


    Or probably you are trying to achieve the following:

    .ClientTemplate(Html.Partial("PartialName").ToHtmlString())

    you do not need to pass any item variable at all - the client expressions inside of the Partial view such as #= # will still work as expected because this template is used on the client.

    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Manoj
    Manoj avatar
    3 posts
    Member since:
    Apr 2011

    Posted 25 Dec 2012 Link to this post

    Thanks for reply.  

    Here is what I am trying to do.

    I want to create a ListView with the Template being a Partial View. 

    1)  My instance of ListView says .ClientTemplate does not exist.  I have the latest bits.. Am I missing something? it allows .ClientTemplateId
    2)  In my loop in the view I need to pass an OBJECT not the  Value.  "item" is this case consists of multiple properties of the product which the partial view will render.  

    Listview.

    @(Html.Kendo().ListView<ProductOverviewModel>(Model.Products)
        .Name("listView")
        .TagName("div")
        .ClientTemplate(Html.Partial("_ProductBox", item).ToHtmlString())
        .DataSource(dataSource =>
        {
            dataSource.Read(read => read.Action("HomepageProducts", "Catalog"));
            dataSource.PageSize(3);
        })
        .Pageable()
    )


    My Current Code that works without Kendo Listview.  I am trying to achieve this using Kendo Listview.

    {
            @(Html.DataList<ProductOverviewModel>(Model.Products, 5,
                @<div class="item-box">
                    @Html.Partial("_ProductBox", item)
                </div>
                    ))
            }
  5. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 26 Dec 2012 Link to this post

    Hi,

    Basically the ListView uses only ClientTemplates you cannot execute C# code in them.

    Could you share a sample project so we can see what exactly is the setup?

    Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
Kendo UI is VS 2017 Ready