首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kendo UI MVC和CodeFluent实体

Kendo UI MVC和CodeFluent实体
EN

Stack Overflow用户
提问于 2013-07-17 11:33:03
回答 1查看 243关注 0票数 0

有没有人使用过Kendo UI Grid控件和CodeFluent entities (www.softfluent.com)生成的MVC解决方案?我遇到了一个障碍,试图返回网格进行AJAX处理所需的JSON结果,我想知道是否有更有经验的开发人员设法克服了这一点。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2015-11-04 18:27:32

这篇文章很旧,但对于遇到困难的其他人来说,这里是我如何在遇到一些困难后让Telerik网格(几乎就是ASP.NET UI网格)使用CodeFluent的。

导入名称空间:

代码语言:javascript
复制
using CodeFluent.Runtime.Utilities;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;
...

然后,在您的read方法中,您现在需要:

  1. 将您的CodeFluent对象集合加载到列表中。
  2. 使用CodeFluent序列化程序将CodeFluent对象集合转换为kendo序列化生成的数据源。其他人似乎在将CodeFluent对象转换为JSON时遇到了各种问题,包括没有正确处理循环引用。

以下是示例代码:

代码语言:javascript
复制
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;
}

现在您只需要设置telerik网格来调用"ReadForGrid“方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17690627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档