0

Has anyone used the Kendo UI Grid control with a CodeFluent entities (www.softfluent.com) generated MVC solution? I have reached a roadblock trying to return the JSON result that the Grid requires for AJAX processing and am wondering if a more experienced developer has managed to overcome this.

Thanks.

user2589758
  • 33
  • 1
  • 5
  • Could you be more specific and show some code, what's the problem? How is the JSON constructed? – Simon Mourier Jul 17 '13 at 06:58
  • Actually, the issue is that CodeFluent Entities does not make use of the Entity Framework as as such trying to use the Kendo DataRequest and ToDataSourceResult to enable AJAX editing does not work - at least out of the box. – user2589758 Jul 23 '13 at 01:34
  • 1
    Indeed, CodeFluent Entities has nothing to do with Entity Framework (beyond the "entity" word) but that does not mean it cannot work with Kendo UI MVC. Please post a more specific question (you can also use the vendor forum) – Simon Mourier Jul 23 '13 at 10:03

1 Answers1

1

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:

  1. Load your CodeFluent object collection, into a list.
  2. Convert CodeFluent object collection to kendo datasource.
  3. 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.

MTran
  • 1,799
  • 2
  • 17
  • 21