Does the Json.Encode() Helper use the JavaScriptSerializer class to encode a string to json?
I am getting a circular reference exception when using Json.Encode(Model) even though my class properties that are being serialized have the [ScriptIgnore] attribute.
My only guess is that maybe the Json.Encode() helper doesn’t use the JavaScriptSerializer to serialize to json but I can’t find the documentation anywhere on msdn.
@Html.Raw(Json.Encode(Model))
Here’s an example of one of the models that has a property that should not be serialized…
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Web.Script.Serialization;
namespace RobotDog.Entities {
public class Character {
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[MaxLength(200)]
public string Name { get; set; }
public virtual Person Person { get; set; }
[ScriptIgnore]
public virtual Movie Movie { get; set; }
}
}
Yes.
From the source code:
where
JavaScriptSerializerisSystem.Web.Script.Serialization.JavaScriptSerializeralso to assist your issue see this thread