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

MVC DataSource

3 Answers 140 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 26 Sep 2013, 06:45 PM
Having trouble getting the sytax right to call a controller and populate a dropdownlist usising a DataSource. getting error:0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'Read'
HTML:
 <div id="divyear">
        <select id="cboYear">
        </select>

    </div>

  <script>
        $(document).ready(function () {
            var yearsSource = new kendo.data.DataSource()
            .Read()
            .Action("getYears", "Glass");

            $("#cboYear").kendoDropDownList({
                AutoBind: false,
                BindTo: Model.YearsList,
                DataValueField: "Value",
                DataTextField: "Text",
                Change: yearChange,
                DataSource: yearsSource,
                ServerFiltering: true
             })

         });
...
Controller:
      [HttpGet]
        public JsonResult getYears()
        {
            GlassModel gm = new GlassModel();
    //gm.YearsList is a SelectList
            return Json(gm.YearsList, JsonRequestBehavior.AllowGet);
        }
Thanks

3 Answers, 1 is accepted

Sort by
0
Bill
Top achievements
Rank 1
answered on 26 Sep 2013, 08:18 PM
Changed code to this, now controller is called but dropdown has no items yearsSource data length is 0
        $(document).ready(function () {
            var yearsSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: "/Glass/getYears",
                        dataType: "json"
                    }
                }
            });
            $("#cboYear").kendoDropDownList({
                AutoBind: false,
                DataValueField: "Value",
                DataTextField: "Text",
                Change: yearChange,
                ServerFiltering: true,
                DataSource: yearsSource
            })
         });
0
Accepted
Alexander Valchev
Telerik team
answered on 27 Sep 2013, 09:15 AM
Hi Bill,

It seems that you are trying to use mixture of JavaScript and MVC Razor syntaxes which will not work.

Note that in JavaScript, configuration properties are typed in camelCase where the first letter is a small one. In other words:
$("#cboYear").kendoDropDownList({
    AutoBind: false, //should be changed to: autoBind: false
      //etc...

In addition, there is no BindTo option (in JS syntax) and serverFiltering is property of the DataSource, not the widget.

My recommendation is to read carefully the corresponding getting started articles and API reference topics.
Last but not least, if you would like to use MVC wrappers for Kendo UI please refer to there topics:
I hope this will help.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bill
Top achievements
Rank 1
answered on 27 Sep 2013, 01:21 PM
Yes, I started with Razor and switched to HTML.
Works now, Thanks
Tags
Data Source
Asked by
Bill
Top achievements
Rank 1
Answers by
Bill
Top achievements
Rank 1
Alexander Valchev
Telerik team
Share this question
or