I have an issue with ListView mvc

11 posts, 1 answers
  1. Marcin
    Marcin avatar
    165 posts
    Member since:
    Jan 2011

    Posted 21 Aug 2012 Link to this post

    The following code does not create list at all:
    @(Html.Kendo()
    .ListView<ReportTypeViewModel>()
    .Name("listView")
    .TagName("ul")
    .DataSource(ds => ds.Read(read => read.Url("/api/ReportApi/List").Type(HttpVerbs.Get)))
    .ClientTemplateId("templateReportList"))

    When I pass list to the constructor by:
    .ListView<ReportTypeViewModel>(types)
    this is working.

    Url "/api/ReportApi/List" is MVC 4 web api.

    However when I checked not MVC version of list the following code works:
    function initList() {
            $("#listview").kendoMobileListView({
                    template: "<a><span>${data.Name}</span></a>",
                    dataSource: new kendo.data.DataSource({
                        transport: {
                            read: "/api/ReportApi/List",
                            type: "json"
                        },
                    }),
                    style: "inset"
                });
        }
    Above is mobile list view. But web also is working without problem. The only issue I have is MVC wrapper.

    UPDATE:
    I've posted this in wrong thread - could you please move it to proper one?
  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 24 Aug 2012 Link to this post

    Hello,

    The Kendo MVC ListView expects the data to be returned in an object with Data as name. For example:

    return new DataSourceResult()
    {
         Data = myData
    };

    Regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Marcin
    Marcin avatar
    165 posts
    Member since:
    Jan 2011

    Posted 15 Sep 2012 Link to this post

    Hello, that makes listview wrapper unusable. I cannot change api return format and do not want to create wrapper to use wrapper. This a bit pity since similar thing is working without issue with chart components, just not with list.
  5. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 19 Sep 2012 Link to this post

    Hello Marcin,

    I am not sure if I understand correctly the problem with the result. Is there no control over the returned data?
    As general information I can say that the ListView wrapper is intended for use with the MVC controllers and the DataSourceResult like described in the ListView Binding documentation topic.

    Kind regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Marcin
    Marcin avatar
    165 posts
    Member since:
    Jan 2011

    Posted 22 Sep 2012 Link to this post

    I'm just saying that to use it in that way I would need to return a wrapper. I want to keep my web api simple, eg list of objects, strings. These lists are perfectly working with chart mvc wrappers, but list view wrapper requires different way of data return. That is way I cannot use it. But I can use native js list view with my simple web api. That is why this is strange for me. Chart working, native js list view as well, but mvc wrappers requires special type of return, which I do not undrestand why?
  7. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 27 Sep 2012 Link to this post

    Hello Marcin,

    The reason why the MVC ListView as well as the Grid require a different result is that they support server paging and need information about the total number of records. The Chart always loads all the data on the client so it can accept a simple JSON array. 

    Regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  8. Marcin
    Marcin avatar
    165 posts
    Member since:
    Jan 2011

    Posted 27 Sep 2012 Link to this post

    Ok, i understand explanation, but not totally. Why only wrapper needs this special data, but native js not. This part has no sense for me, since wrapper just generates js on the web site. I can create simple JavaScript list using my web api. I cannot use wrapper for generate the same result. I always was thinking that wrappers are for simplify code in views, but I cannot achieve the same result as with native java script. That's why I stepped using wrappers at all, l can achieve much more without wrappers using much simpler code. I started my application with mvc wrappers and it looked simple, then I stucked with limitations and totally removed mvc reference. Now I cannot find any reason to use mvc wrappers any more. They generate more code, they have limitations that native js classes not, they have lack of help.
  9. Eric
    Eric avatar
    21 posts
    Member since:
    Mar 2012

    Posted 01 Oct 2012 Link to this post

    The ToDataSourceResult extension method makes it easy to return any IEnumerable as a DataSourceResult. Just add the using statement Kendo.Mvc.Extensions and you can call that extension method on any IEnumerable.

    Here is a simple example of a method on a controller that does this from the MVC Examples project:
    public ActionResult Products_Read([DataSourceRequest] DataSourceRequest request)
    {
        return Json(GetProducts().ToDataSourceResult(request));
    }
  10. Marcin
    Marcin avatar
    165 posts
    Member since:
    Jan 2011

    Posted 02 Oct 2012 Link to this post

    Hello, Like I've written before I do not intent to use MVC wrappers any more. Too many limitationas and behavior different than normal native java script. I will use native java script since it is easier, allows simpler code and supports much more features.

    About your answer:
    a) this is not solution for me since I'm using web api (MVC 4), that ia available for many application. So changing result of web api by creating wrapper to use wrapper has totally no sense for me.
    b) like I written before I can use result from my web api (MVC 4) without changing anything in native kendo  javascript ListView (see my first post), and in fact I didn't receive any explanation why I can use this in java script ListView, but wprapper which on output creates such java script represenation can not use such api.
    c) You are saying that listview requires special type which contains Data field. But this is not true, becuase I can use list without such special data when I'm not using wrapper.

  11. Answer
    Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 02 Oct 2012 Link to this post

    Hello,

    The wrappers are designed to use the Kendo MVC server API and therefore have some predefined options set. The reason why the Data and Total fields are needed in the response, is that the schema data and total are set:

    schema:{
        data: "Data",
        total:"Total"
    Regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  12. Marcin
    Marcin avatar
    165 posts
    Member since:
    Jan 2011

    Posted 02 Oct 2012 Link to this post

    Thank you
    Now I understand.
Back to Top
UI for ASP.NET MVC is VS 2017 Ready