JsonIgnore not working in System.Web.Mvc.Controller
The JsonResult
in MVC does not actually use JSON.NET which is why [JsonIgnore]
is not working. Instead it uses the JavaScriptSerializer
class.
To make the JavaScriptSerializer
skip a property, you can you the [ScriptIgnore]
attribute on your model property.
An alternative would be to make a custom ActionResult
that uses JSON.NET's JsonConvert
to serialize the object which would then honor the [JsonIgnore]
attribute.