I have a big problem populating a kendo combobox with json data sent from controller in an ASP.NET MVC3 project.
My controller:
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:
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!
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!