English 中文(简体)
为什么从mvc返回json时IgnoreDataMember属性不起作用?
原标题:Why isn t the IgnoreDataMember attribute working when returning json from mvc?

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

return Json(db.Pages.ToList(), JsonRequestBehavior.AllowGet);

我试着用

[IgnoreDataMember]

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

我在这里找到了一篇文章,其中指出以这种方式返回json将使用JavaScriptSerializer,我尝试使用[ScriptIgnore],但vs2010没有将其识别为有效属性http://teamezy.blogspot.com/2008/12/making-jsonresult-in-mvc-ignore.html

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

最佳回答

ScriptIgnoreAttribute位于System.Web.Script.Serialization命名空间中-是否有适当的使用指令并引用System.Web.Extensions程序集?

请记住将ProxyCreationEnabled设置为false。

context.Configuration.ProxyCreationEnabled = false;
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签