This post is old, but for anyone else who hits a road block, here's how I got Telerik's ASP.NET MVC Grid (Which is pretty much Kendo UI Grid) to work with CodeFluent after some difficulties.
Import the namespaces:
using CodeFluent.Runtime.Utilities;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;
...
Then, in your read method, you now need:
- Load your CodeFluent object collection, into a list.
- Convert CodeFluent object collection to kendo datasource.
- Convert the resulting datasource to JSON, using CodeFluent serializer. Others seems to have various issues converting CodeFluent objects to JSON, which includes not handling circular referencing correctly.
Here's the sample code:
public ActionResult ReadForGrid([DataSourceRequest]DataSourceRequest request)
{
//Convert CodeFluent collection of objects to a list.
List<MyCodeFluentModel> CFECollectionList = new List<MyCodeFluentModel>();
foreach (MyCodeFluentModel aCodeFluentModel in MyCodeFluentModelCollection.LoadAll())
{
CFECollectionList.Add(new MyCodeFluentModel(fileMetaData));
}
//Convert the list to a DataSourceResult
//Which is a formatted object suitable to be returned to the grid.
DataSourceResult dataSourceResult = CFECollectionList.ToDataSourceResult(request);
//Convert the DataSourceResult to JSON, and return it.
return ConvertToJsonResponse(dataSourceResult);
}
public static ContentResult ConvertToJsonResponse(object obj)
{
string json = JsonUtilities.Serialize(obj);
return PrepareJson(json);
}
public static ContentResult PrepareJson(string json)
{
ContentResult content = new ContentResult();
content.Content = json;
content.ContentType = "application/json";
return content;
}
And now you just need to setup the telerik grid to call the "ReadForGrid" method.