从mvc返回json时,为什么IgnoreDataMember属性不起作用?

Tom*_*Tom 4 c# asp.net-mvc json asp.net-mvc-3

我正在从MVC控制器动作返回一个JsonResult,并且一直试图删除一个属性但没有太多的快乐.

return Json(db.Pages.ToList(), JsonRequestBehavior.AllowGet);
Run Code Online (Sandbox Code Playgroud)

我已经尝试装饰我的课程

[IgnoreDataMember]
Run Code Online (Sandbox Code Playgroud)

属性,并在类的其他属性上使用[DataContract]和[DataMember]属性,但这似乎被忽略.

我在这里发现了一个帖子,它声明以这种方式返回json将使用JavaScriptSerializer,我尝试使用[ScriptIgnore],但vs2010不会将此识别为有效属性.http://teamezy.blogspot.com/2008/12/making-jsonresult-in-mvc-ignore.html

我是否需要以不同的方式返回数据才能使IgnoreDataMember或DataContract/DataMember工作?

Jon*_*eet 15

ScriptIgnoreAttributeSystem.Web.Script.Serialization命名空间中 - 您是否有适当的using指令和对System.Web.Extensions程序集的引用?

记得设置ProxyCreationEnabled为false.

context.Configuration.ProxyCreationEnabled = false;
Run Code Online (Sandbox Code Playgroud)