ListView template with unnamed Datasource members

6 posts, 0 answers
  1. Cristina
    Cristina avatar
    6 posts
    Member since:
    Apr 2016

    Posted 17 May Link to this post

    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>

  2. Venelin
    Admin
    Venelin avatar
    352 posts

    Posted 19 May Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Cristina
    Cristina avatar
    6 posts
    Member since:
    Apr 2016

    Posted 19 May in reply to Venelin Link to this post

    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?
  5. Venelin
    Admin
    Venelin avatar
    352 posts

    Posted 20 May Link to this post

    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
  6. Cristina
    Cristina avatar
    6 posts
    Member since:
    Apr 2016

    Posted 20 May in reply to Venelin Link to this post

    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. 
  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 24 May Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready