[{"Active":true,"DisplayText":"Flyers","TemplateCategoryID":1},{"Active":true,"DisplayText":"Door Hangers","TemplateCategoryID":2},{"Active":true,"DisplayText":"Postcards","TemplateCategoryID":3},{"Active":true,"DisplayText":"Tri-Fold","TemplateCategoryID":4},{"Active":true,"DisplayText":"Facebook Graphics","TemplateCategoryID":5}]@(Html.Kendo().ComboBox() .Name("templateCat") //The name of the combobox is mandatory. It specifies the "id" attribute of the widget. .DataTextField("DisplayText") //Specifies which property of the Product to be used by the combobox as a text. .DataValueField("TemplateCategoryID") //Specifies which property of the Product to be used by the combobox as a value. .Filter(FilterType.Contains) .DataSource(source => { source.Read(read => { read.Action("GetTemplateCategories", "Console"); //Set the Action and Controller name }); }) .SelectedIndex(0) //Select first item.)public ActionResult GetTemplateCategories(){ string baseAddress = string.Format(ConfigurationManager.AppSettings["MarketingServiceAddress"] + "GetTemplateCategories"); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(baseAddress); request.Method = "GET"; request.ContentType = "text/plain"; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { int statusCode = (int)response.StatusCode; StreamReader reader = new StreamReader(response.GetResponseStream()); string results = reader.ReadToEnd(); return Json(results, JsonRequestBehavior.AllowGet); }}$(
"#openButton").click(function () {
var window1 = $("#window").kendoWindow({
content: "Test.html",
title: " Window Content",
modal: true });
var window = $("#window").data("kendoWindow");
window.center();
window.open(); });
Thanks in advance.
@model iProjX.Models.RolesModel@using iProjX.Models;<script type="text/x-kendo-tmpl" id="rolesList"> <h3> ${Id} ${Description}</h3></script><div id="listView"></div><div class="k-pager-wrap"> <div id="pager"></div></div><script type="text/javascript"> var projectId = @(Html.Raw(Model.ProjectId)); var sharedDataSource = new kendo.data.DataSource({ transport: { read: { url: "http://localhost:1278/Project/getRoles", type: "POST" } }, change: function (data) { debugger; alert("success "); }, error: function (xhr, error) { debugger; alert("error "); }, pageSize: 3 }); //Configure the List $("#listView").kendoListView({ pageable: true, selectable: true, navigatable: true, template: kendo.template($("#rolesList").html()), dataSource: sharedDataSource }); //Configure the Pager $("#pager").kendoPager({ dataSource: sharedDataSource }); </script>
And my controller contains
public JsonResult getRoles([DataSourceRequest] DataSourceRequest request) { var projectId = 113; using (LocationRepositry _locationRepository = new LocationRepositry()) { IEnumerable<myLocation> Locations = _locationRepository.getByProjectId_Simple(projectId).Select(p => new myLocation() { Id = p.Id, Description = p.Description }).ToList(); return Json(Locations.ToDataSourceResult(request)); }}And myLocation is
public class myLocation{ public myLocation() {} public Int64 Id { get; set; } public String Description { get; set; }}Now, with this implementation my controller function getRoles is hit and I can see the data returned from the server via browser tools as below.
Data returned from server
{"Data":[{"Id":132,"Description":"Location 1"},{"Id":133,"Description":"Location 2"},{"Id":134,"Description":"Location 3"},{"Id":135,"Description":"Location 4"}],"Total":4,"AggregateResults":null,"Errors":null}
The change function on the datasource is then subsequently hit but the data parameter returned contains an empty set of Data items as below (taken from visual studio immediate window).
?data{...} items: [] sender: {...} preventDefault: function(){g=!0} isDefaultPrevented: function(){return g}
If I change my controller to return without using the ToDataSourceResult extension it actually will work.
return Json(Locations);
However, is this then the correct implementation or have I done something else wrong? And would this have an effect on how paging works?
Any help would be much appreciated.
Thanks