asp.net-mvc – Web API错误:’ObjectContent`1’类型无法序列化内容类型的响应正文
|
我在尝试使用Web API控制器时收到此错误.
我的控制器中的代码如下 public IEnumerable<Student> GetAllStudents()
{
var allstudents = unitOfWork.StudentRepository.Get(includeProperties: "Groups");
return allstudents;
}
public Student GetStudentByID(Guid id)
{
return unitOfWork.StudentRepository.GetByID(id);
}
我的’学生’课程如下 public partial class Student
{
public Student()
{
this.Groups = new HashSet<Group>();
}
public System.Guid StudentID { get; set; }
public string Surname { get; set; }
public string FirstName { get; set; }
public byte[] Timestamp { get; set; }
public virtual Course Course { get; set; }
public virtual ICollection<Group> Groups { get; set; }
}
两种方法都会导致相同的错误. 我内心的例外情况如下
我有一种感觉,我需要使用KnownType属性,但我不确定如何实现它. 任何帮助,将不胜感激 解决方法什么是内部异常消息?内部异常消息将是序列化程序抛出的实际异常,它应该告诉我们哪种类型导致异常.让我猜一下 – 它是类型课程和类型组吗?如果是这样,请尝试将KnownType属性放在类Student的实际实现类型上 [KnownType(typeof(GroupA))]
[KnownType(typeof(CourseA))]
public partial class Student
{...}
public class GroupA : Group {...}
public class CourseA : Course {...}
public interface Group {...}
public interface Course {...} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 在ASP.net C#中伪造浏览器请求
- asp.net-mvc – ModelState.AddModelError编码HTML
- entity-framework – 在Junction表上使用EF Core ThenInclu
- asp.net-mvc – .net mvc的简短/快速解释
- asp.net-mvc-3 – ASP.NET MVC 3未找到视图“错误”或其主文
- asp.net-mvc-2 – Plus()在MVC中的参数引起404在IIS 7.0
- asp.net-mvc – 为什么我不能从Web平台安装程序安装ASPNET
- 在ASP.NET(C#)中实现安全,独特的“一次性”激活URL
- asp.net-mvc – 如何设置html.EditorFor helper的大小?
- 如何在asp.net webform中使用异步/等待实现异步页面?
- 如何在ASP.NET Membership Cookie中存储自定义数
- 如何阻止ASP.NET Menu控件生成内联html样式元素
- asp.net-web-api – ASP.NET WebAPI OData – 继
- asp.net – AJAX和FormsAuthentication,如何防止
- asp.net – HTML属性bgcolor已被弃用:使用什么?
- asp.net-mvc – 使用实体框架4.1创建复合主键
- asp.net-mvc – ASP.net MVC DropDownList预选项
- asp.net-mvc – 尝试确定在干净安装的窗口上托管
- asp.net-mvc – asp.net mvc针对不同操作的不同验
- 如何在ASP.NET Core MVC 6中强制执行小写路由?
