包含空集合的MVC3代码第一个模型似乎是JSON的问题 [英] MVC3 code first Model containing an empty collection appears to be a problem with JSON

查看:55
本文介绍了包含空集合的MVC3代码第一个模型似乎是JSON的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是否是正确的论坛请告诉我,如果不是,我会纠正。

I'm not sure if this is the right forum please let me know and I'll correct if it isn't.

我有一个引用另一个的模型通过ICollection建模。

I have a Model that references another Model through an ICollection.

我正在使用jQuery getJSon将数据加载到Index.cshtml中。

I'm using jQuery getJSon to load the data into the Index.cshtml.

当ICollection不属于模型在浏览器中正确返回和处理数据。

When the ICollection is not part of the Model the data is returned and processed in the browser correctly.

当ICollection在模型中时,我可以验证数据是否返回到控制器,因为数据尚未创建对于ICollection,它显示零记录的计数。但是,返回浏览器的内容似乎会导致脚本
出错。 

When the ICollection is in the Model, I can verify the data is returned to the controller and since the data has not been created for the ICollection it shows a count of zero records. However, what ever is returned to the browser appears to cause the script to error. 

 

任何想法什么可能导致JSON格式错误?

Any thoughts on what might cause the JSON to be malformed?

 

推荐答案

多一点信息,我能够检查ajax电话的回复,我收到以下错误

A little bit more information, I was able to inspect the reply from the ajax call and I'm getting the following error

 

检测到循环引用序列化类型为'System.Data.Entity.DynamicProxies.zzzzz'的对象时

A circular reference was detected while serializing an object of type 'System.Data.Entity.DynamicProxies.zzzzz'

 

我收到此错误即使手动为集合创建实例,因此iCollection计数是否为1或0。

I'm getting this error even if manually create an instance for the collection, so whether the iCollection count = 1 or 0.


这篇关于包含空集合的MVC3代码第一个模型似乎是JSON的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆