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

Unable to assign data to dataSource in kendoComboBox

0 Answers 157 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Cosmin
Top achievements
Rank 1
Cosmin asked on 14 Jun 2012, 02:26 PM
I have a big problem populating a kendo combobox with json data sent from controller in an ASP.NET MVC3 project.
My controller:

public JsonResult Index()
{
  StreamReader sr = null;
  string json = string.Empty;
 
  WebRequest request = WebRequest.Create("http://192.168.1.8:99/GetClienti?format=json");
 
  using (WebResponse response = request.GetResponse())
  {
    sr = new StreamReader(response.GetResponseStream(), true);
    json = sr.ReadToEnd();
  }
 
   int index = json.IndexOf('[');
   json = json.Substring(index);
   index = json.LastIndexOf(']');
   json = json.Substring(0, json.Length + 1 - Math.Abs(index - json.Length));
 
 
  return Json(json, JsonRequestBehavior.AllowGet);
}

I am modifying the returned string to be an array of objects (dataSource works only for arrays from what I have read)

In the html file:
...
<input id="kendoCboClienti" />
...
<script type="text/javascript">
    $(document).ready(function () {
    $("#kendoCboClienti").kendoComboBox({
            placeholder: "Sceglie il cliente",
            dataTextField: "RAGIONE_SOCIALE",
            dataValueField: "ID",
            dataSource: {
                transport: {
                    read: {
                        url: "/Clienti/",
                        dataType: "json"
                    }
                },
                schema: {
                    model: {
                        fields: {
                            id: { type: "number" },
                            ragioneSociale: { type: "string" }
                        }
                    }
                }
            }
        });
    });
</script>

In the attachment below is the json the controller returns. The combobox control doesn't show anything, just the loading image in the right.

It's a problem with the Json? If I declare it locally, it works (in firebug appears like an object array of objects). The dataSource can't parse it? It's because of the json is like a string, in the " ? I don't know what the problem might be, I spent too many time trying to understand this..

Please help! Thanks!

No answers yet. Maybe you can help?

Tags
Data Source
Asked by
Cosmin
Top achievements
Rank 1
Share this question
or