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

ListView Template trying to add a partial View

3 Answers 589 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Manoj
Top achievements
Rank 1
Manoj asked on 23 Dec 2012, 01:55 AM
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()        
)
        

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 25 Dec 2012, 01:15 PM
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!
0
Manoj
Top achievements
Rank 1
answered on 25 Dec 2012, 07:04 PM
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>
                ))
        }
0
Petur Subev
Telerik team
answered on 26 Dec 2012, 09:20 AM
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!
Tags
Templates
Asked by
Manoj
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Manoj
Top achievements
Rank 1
Share this question
or