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

ListView template with unnamed Datasource members

5 Answers 145 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Cristina
Top achievements
Rank 1
Cristina asked on 17 May 2016, 02:00 PM

I am binding a ListView to a collection of strings.  How can I access that data in the template definition? Model.SearchResults is a type of IEnumberable<string>

@(Html.Kendo().ListView(Model.SearchResults)
    .Name("listClients")
    .TagName("div")
    .ClientTemplateId("clientsTemplate")
    .Pageable(pageable => pageable
        .PreviousNext(true)
        .Info(true)
        .PageSizes(true))
    .HtmlAttributes(new{style="min-height:300px"})
    .DataSource(dataSource => dataSource
         
        .PageSize(1)))
 
<script type="text/x-kendo-tmpl" id="clientsTemplate">
       @Html.Action("LoadProfileView", new { clientId = **HOW DO I GET THE VALUE HERE**})
</script>

5 Answers, 1 is accepted

Sort by
0
Venelin
Telerik team
answered on 19 May 2016, 06:56 AM
Hi Cristina,

Please refer to this help article: http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/listview/overview#setup

Regards,
Venelin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Cristina
Top achievements
Rank 1
answered on 19 May 2016, 02:56 PM
I apologize if I am confused, but I don't see what that article has to do with my question.  Clearly I know how to setup the ListView, as you can see in the code that is part of the initial question.  I don't see anything in the setup article that address the template context or anything else having to do with my issue.  Can you please explain what solution you are directing me to?
0
Venelin
Telerik team
answered on 20 May 2016, 09:00 AM
Hi Cristina,

Sorry, for some reason I thought the problem is in the treelist binding. To answer the question "How can I access that data in the template definition?" this can be done by using the reserved variable "data":

<script type="text/x-kendo-tmpl" id="clientsTemplate">
   #:data#
</script>

Attached is a simple example.

Howerver, I am not sure what are you trying to achieve with the @Html.Action... code, could you please explain further?

Regards,
Venelin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Cristina
Top achievements
Rank 1
answered on 20 May 2016, 01:15 PM
I'm trying to load a partial view with a different model than the one for the main view. So I want to pass a client ID as a parameter to the controller action to build the ViewModel then return the partial view. I had actually tried using "#= data #" but it just sent that as a literal string, not the value of the current list item. 
0
Maria Ilieva
Telerik team
answered on 25 May 2016, 09:43 AM
Hi Cristina,

Try using the syntax below for passing the actual data:

#:data#


Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ListView
Asked by
Cristina
Top achievements
Rank 1
Answers by
Venelin
Telerik team
Cristina
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or