开发者

Why isn't the IgnoreDataMember attribute working when returning json from mvc?

开发者 https://www.devze.com 2023-02-10 14:37 出处:网络
I\'m returning a JsonResult from an MVC controller action , and have been trying to remove one attribute but not having much joy.

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号