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

I have an issue with ListView mvc

10 Answers 349 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Marcin
Top achievements
Rank 1
Veteran
Marcin asked on 21 Aug 2012, 09:54 AM
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?

10 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 24 Aug 2012, 10:17 AM
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!
0
Marcin
Top achievements
Rank 1
Veteran
answered on 15 Sep 2012, 05:33 AM
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.
0
Daniel
Telerik team
answered on 19 Sep 2012, 04:16 PM
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!
0
Marcin
Top achievements
Rank 1
Veteran
answered on 22 Sep 2012, 05:10 PM
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?
0
Daniel
Telerik team
answered on 27 Sep 2012, 07:32 AM
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!
0
Marcin
Top achievements
Rank 1
Veteran
answered on 27 Sep 2012, 02:33 PM
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.
0
Eric
Top achievements
Rank 1
answered on 01 Oct 2012, 07:13 PM
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));
}
0
Marcin
Top achievements
Rank 1
Veteran
answered on 02 Oct 2012, 08:02 AM
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.

0
Accepted
Daniel
Telerik team
answered on 02 Oct 2012, 08:46 AM
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!
0
Marcin
Top achievements
Rank 1
Veteran
answered on 02 Oct 2012, 09:06 AM
Thank you
Now I understand.
Tags
ListView
Asked by
Marcin
Top achievements
Rank 1
Veteran
Answers by
Daniel
Telerik team
Marcin
Top achievements
Rank 1
Veteran
Eric
Top achievements
Rank 1
Share this question
or