分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

mvc EF框架中,加载外键对象序列化对象时报错 序列化类型为XX的对象时检测到循环引用

发布时间:2023-09-06 01:52责任编辑:白小东关键词:暂无标签

Newtonsoft.Json.dll 或者通过-》工具-》库程序包管理工具-》NuGet管理包-》联机 输入Newtonsoft或者json.net

Newtonsoft.Json是可以的:

context.Response.ContentType = "text/plain";
BooksService service = new BooksService();
List<Books> ?list=service.GetAll().Take(5).ToList();
JsonSerializerSettings setting = new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};

strintret = JsonConvert.SerializeObject(list, setting);
context.Response.Write(ret);

easyui 代码

$(‘#BooKlist‘).datagrid({
url: ‘BookHandler.ashx?flag=GetBookList‘,
pagination: true,
pageList: [5, 15, 20, 25],
pageSize: 5,
columns: [[
{ field: ‘Title‘, title: ‘书名‘, width: 120 },
{ field: ‘Author‘, title: ‘作者‘, width: 120 },
{ field: ‘ISBN‘, title: ‘ISBN‘, width: 120 },
{
field: ‘Publishersid‘, title: ‘出版社‘, width: 120,
formatter: function (value, row, index) {
return row.Publishers.Name;
}

},
???{
???field: ‘CategoryId‘, title: ‘书类别‘, width: 120,
???formatter: function (value, row, index) {
???return row.Categories.Name;
???}
???}

]]
});

mvc EF框架中,加载外键对象序列化对象时报错 序列化类型为XX的对象时检测到循环引用

原文地址:https://www.cnblogs.com/wlzhang/p/8994243.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved