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-mvc – 带SelectList Design Decison的ViewModels
- asp.net – “共享主机中的”LOG_BACKUP“的数据库的事务日
- asp.net-mvc-4 – 无法从程序集’itextsharp,Version = 5.5
- asp.net-mvc – 使用Facebook和Twitter登录ASP.NET Web API
- 动手造轮子:实现一个简单的依赖注入(三) --- 支持属性注入
- asp.net-mvc – 相同的项目解决方案或同一解决方案中的新项
- asp.net – MVC 4 – 在局部视图中使用不同的模型
- asp.net-mvc – T4MVC基本控制器没有默认构造函数
- 了解ASP.Net会话的生命周期
- 为Asp.Net MVC中的特定Controller或Action启用SSL客户端证书