Return Json to jQuery using ASP.NET MVC
I have this code.
Models.Person p = new testmvc.Models.Person { Firstname = "yongeks", Lastname = "ucab" };
Models.Person p2 = new testmvc.Models.Person { Firstname = "lyn", Lastname = "torreon" };
string q = JavaScriptConvert.SerializeObject(new String[] { JavaScriptConvert.SerializeObject(p), JavaScriptConvert.SerializeObject(p2) });
Console.WriteLine(q);
return q;
I need to parse this code into jquery .. using json request .. can someone help me ..
0
source to share
2 answers
I enjoy working with the Newtonsoft json library. this allows you to control the json serialization process so you can tell what to do with null values, etc.
eg
JsonNetResult jsonNetResult = new JsonNetResult();
jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
jsonNetResult.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
jsonNetResult.Data = nodes
return jsonNetResult;
+4
source to share