asp.net – WebAPI Empty 500错误
发布时间:2020-12-16 06:25:02 所属栏目:asp.Net 来源:网络整理
导读:我遇到了WebAPI的问题,返回空500. 这是数据类. public class Comment{ public int Id { get; set; } public string Content { get; set; } public string Email { get; set; } public bool IsAnonymous { get; set; } public int ReviewId { get; set; } pub
我遇到了WebAPI的问题,返回空500.
这是数据类. public class Comment { public int Id { get; set; } public string Content { get; set; } public string Email { get; set; } public bool IsAnonymous { get; set; } public int ReviewId { get; set; } public Review Review { get; set; } } public class Review { public int Id { get; set; } public string Content { get; set; } public int CategoryId { get; set; } public string Topic { get; set; } public string Email { get; set; } public bool IsAnonymous { get; set; } public virtual Category Category { get; set; } public virtual ICollection<Comment> Comments { get; set; } } 这是来自ReviewRepository.cs的代码 public Review Get(int id) { return _db.Reviews.Include("Comments").SingleOrDefault(r => r.Id == id); } 以及来自ReviewController.cs的代码 public HttpResponseMessage Get(int id) { var category = _reviewRepository.Get(id); if (category == null) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK,category); } 无论我做什么,从/ api / reviews / 1返回的响应都是500错误.调试时,类别是正确的,加载了所有注释. 我尝试了GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;,但这没有帮助.我在这里不知所措! 解决方法
我猜它是因为你有一个圆形对象图,这将导致序列化错误.
http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization#handling_circular_object_references (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – “用户首选项”数据库表设计
- ASP.NET WebSite发布与复制?
- asp.net-web-api – Swagger WebApi在构建时创建json
- asp.net-mvc – 服务层验证
- CKEditor数据绑定在asp.net核心mvc中
- asp.net-core – 在定位.NET Core时引用旧的(完整的.NET Fr
- asp.net – aspnet_regiis不存在
- asp.net-mvc – ValidateAntiForgeryToken属性
- asp.net – 帮助捕获StackOverflowException与WinDbg和ADPl
- asp.net-mvc – 当参数为Model时,ASP.NET MVC发布文件模型绑
推荐文章
站长推荐
- asp.net-mvc – MVC3如何禁用/启用ActionLink
- asp.net – HttpContext.Cache到期
- asp.net – 使用Entity Framework的仓库模式(mvc
- 当ASP.NET验证失败时,更改文本框的css类
- asp.net-mvc – ASP.NET MVC下拉列表
- asp.net – Repeater的SeparatorTemplate与Eval
- 如何使用asp .net web api,实体框架和json(代码优
- 在updatepanel asp.net c#中的AsyncFileUpload中
- asp.net-mvc-4 – 错误:无法将lambda表达式转换
- asp.net-mvc-3 – 为什么我的IgnoreRoute不起作用
热点阅读