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

Loading Datasources

3 Answers 215 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Rhys
Top achievements
Rank 1
Rhys asked on 18 Apr 2012, 10:17 AM
Hi,

today i have tried to read the data out of a datasource....

i have just seen this post: http://www.kendoui.com/forums/framework/mvvm/mvvm-source-binding-to-datasource.aspx

which is bascially what i have been trying to do all day.

tho trying the answer doesn't work, when using kendo.bind($("#container"), a); it Never hits the controller action method (using MVC3) leading me to believe that the datasource never calls the server.

VIEW:
 
@section ViewModel
{
    <script type="text/javascript">
        $(function () {
            var a = kendo.observable({
                theList: new kendo.data.DataSource({
                    transport: {
                        read: "/home/zaza",
                        dataType: "json",
                        type: "POST"
                    },
                    schema: {
                        model: {
                            id: "ID",
                            fields: {
                                ID: {
                                    editable: false,
                                    nullable: false
                                },
                                Name: {
                                    editable: true,
                                    nullable: true
                                }
                            }
                        }
                    }
                })
            });
 
            kendo.bind($("#container"), a);
        });
    </script>
}
 
<h2>@ViewBag.Message</h2>
<div id="container">
        <ul data-role="listview" data-template="ul-template" data-bind="source: theList">
        </ul>
</div>
<script id="ul-template" type="text/x-kendo-template">
<li>
    id: <span data-bind="text: ID"></span>
    name: <span data-bind="text: Name"></span>
</li>
</script>
 
HOME - CONTROLLER:
 
 public class Place
        {
            public int ID { get; set; }
            public string Name { get; set; }
        }
 
 
        [HttpPost]
        public JsonResult zaza()
        {
             
            List<Place> plases = new List<Place>();
 
            plases.Add(new Place() { ID = 0, Name = "Larocque" });
            plases.Add(new Place() { ID = 1, Name = "St-Louis" });
            plases.Add(new Place() { ID = 2, Name = "Dorval" });
            plases.Add(new Place() { ID = 3, Name = "St-Pierre" });
 
 
 
            return Json(plases, JsonRequestBehavior.DenyGet);
        }


I have had limited success creating a datasource and calling read() on it, but could never get the data out afterwards.

what im trying to do:

1) define #view with binding templates
2) read remote datasource
3) bind that data array (from item 2) to a viewModel property (viewModel.Groups = data???)
4) bind the viewModel to the view (using kendo.bind($("#view"), viewModel);)


I have foudn this very hard to do... 

I should say im a Noob to javascript so maybe im making a basic silly mistake... but for the life of me i can figure out what.

Thank you in advance

Rhys Walden

3 Answers, 1 is accepted

Sort by
0
Rhys
Top achievements
Rank 1
answered on 18 Apr 2012, 07:41 PM
i am using Firefox and firebug. firebug is not showing ANY call to my controller. (other than the first call to load the page)

i have forced the read (using a.theList.Read()) and it returns with the following data:
[{"ID":0,"Name":"Larocque"},{"ID":1,"Name":"St-Louis"},{"ID":2,"Name":"Dorval"},{"ID":3,"Name":"St-Pierre"}]

(and the breakpoints on the controller hits)

but even doing this, nothing is showing in the list on screen using the data template other than the words
undefined.

The scripts i am using for this are:
  • jQuery 1.7.2
  • kendo.web.min.js
  • kendo.data.min.js



0
Rhys
Top achievements
Rank 1
answered on 19 Apr 2012, 08:35 AM
Hi,

I just tried my page with the kendo.all.js file and that has fixed the problem.
0
SA-Ignite
Top achievements
Rank 1
answered on 14 Jul 2012, 03:55 AM
I just had the same issue... I was using kendo.web.min and kendo.dataviz.min together.  Switching to kendo.all.min solved the issue.
Tags
Data Source
Asked by
Rhys
Top achievements
Rank 1
Answers by
Rhys
Top achievements
Rank 1
SA-Ignite
Top achievements
Rank 1
Share this question
or