Why does the IgnoreDataMember attribute not work when returning json from mvc?

I am returning JsonResult from an MVC controller action and trying to remove a single attribute, but not getting much joy.

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

I tried decorating my class, which returns with

 [IgnoreDataMember] 

and using the [DataContract] and [DataMember] attributes for other class attributes, but this seems to be ignored.

I found a message here where it states that returning json this way will use this JavaScriptSerializer, I tried using [ScriptIgnore], but vs2010 does not recognize this as a valid attribute. http://teamezy.blogspot.com/2008/12/making-jsonresult-in-mvc-ignore.html

Do I need to return data differently to work with IgnoreDataMember or DataContract / DataMember materials?

+4
source share
1 answer

ScriptIgnoreAttribute is located in the System.Web.Script.Serialization - you have the corresponding using directive and a reference to the System.Web.Extensions assembly

Remember to set ProxyCreationEnabled to false.

 context.Configuration.ProxyCreationEnabled = false; 
+14
source

Source: https://habr.com/ru/post/1339642/


All Articles