The first solution works with the grid editing mode, but we have the same problem with loading the grid, which already has lines of objects with a round link, and to solve this problem we need to create a new IClientSideObjectWriterFactory and a new IClientSideObjectWriter. This is what I do:
1- Create a new IClientSideObjectWriterFactory object:
public class JsonClientSideObjectWriterFactory : IClientSideObjectWriterFactory { public IClientSideObjectWriter Create(string id, string type, TextWriter textWriter) { return new JsonClientSideObjectWriter(id, type, textWriter); } }
2- Create a new IClientSideObjectWriter, this time I do not implement the interface, I inherited ClientSideObjectWriter and redefined the AppendObject and AppendCollection methods:
public class JsonClientSideObjectWriter : ClientSideObjectWriter { public JsonClientSideObjectWriter(string id, string type, TextWriter textWriter) : base(id, type, textWriter) { } public override IClientSideObjectWriter AppendObject(string name, object value) { Guard.IsNotNullOrEmpty(name, "name"); var data = JsonConvert.SerializeObject(value, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new PropertyNameIgnoreContractResolver() }); return Append("{0}:{1}".FormatWith(name, data)); } public override IClientSideObjectWriter AppendCollection(string name, System.Collections.IEnumerable value) { public override IClientSideObjectWriter AppendCollection(string name, System.Collections.IEnumerable value) { Guard.IsNotNullOrEmpty(name, "name"); var data = JsonConvert.SerializeObject(value, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new PropertyNameIgnoreContractResolver() }); data = data.Replace("<", @"\u003c").Replace(">", @"\u003e"); return Append("{0}:{1}".FormatWith((object)name, (object)data)); } }
NOTE. Replace it, because the grid displays html tags for the client template in edit mode, and if we donโt encode, the browser will display the tags. I have not yet found the desktop if I have not used the Replace from string object.
3- On my Application_Start on Global.asax.cs, I registered my new factory as follows:
DI.Current.Register<IClientSideObjectWriterFactory>(() => new JsonClientSideObjectWriterFactory());
And it worked for all the components that Telerik has. The only thing I haven't changed is PropertyNameIgnoreContractResolver, which was the same for EntityFramework classes.