有没有人使用过Kendo UI Grid控件和CodeFluent entities (www.softfluent.com)生成的MVC解决方案?我遇到了一个障碍,试图返回网格进行AJAX处理所需的JSON结果,我想知道是否有更有经验的开发人员设法克服了这一点。
谢谢。
发布于 2015-11-04 18:27:32
这篇文章很旧,但对于遇到困难的其他人来说,这里是我如何在遇到一些困难后让Telerik网格(几乎就是ASP.NET UI网格)使用CodeFluent的。
导入名称空间:
using CodeFluent.Runtime.Utilities;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;
...然后,在您的read方法中,您现在需要:
以下是示例代码:
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“方法。
https://stackoverflow.com/questions/17690627
复制相似问题