I'm returning a JsonResult from an MVC controller action , and have been trying to remove one attribute but not having much joy.
return Json(db.Pages.ToList(), JsonRequestBehavior.AllowGet);
I have tried decorating my class that is being returned with the
[IgnoreDataMember]
attribute, and using [DataContract] and [DataMember] attributes on other attributes on the class but this seems to be ignored.
I 开发者_StackOverflow中文版found a post here where it states that returning json in this way will use that JavaScriptSerializer, I tried using [ScriptIgnore] but vs2010 doesn't recognise this as a valid attribute. http://teamezy.blogspot.com/2008/12/making-jsonresult-in-mvc-ignore.html
Do I need to return data in a different way in order for the IgnoreDataMember or DataContract / DataMember stuff to work?
ScriptIgnoreAttribute
is in the System.Web.Script.Serialization
namespace - do you have an appropriate using
directive and reference to the System.Web.Extensions
assembly?
Remember to set ProxyCreationEnabled
to false.
context.Configuration.ProxyCreationEnabled = false;
精彩评论