AspNetx 0 Report post Posted June 20, 2015 Hello everyone!I need your help.I have this code: @BuildTreeView(treeView, IdCategoriaParente) @helper BuildTreeView(IEnumerable<dynamic> data, int catfiglia, int? idcategoriaparente = 1, int level = 0, string accumulatore = ""){ // // var selectRecord = ""; var nodes = data.Where(n => n.IdCategoriaParente == idcategoriaparente).OrderBy(n => n.Id); var separatore = ""; if (nodes.Any()) { if (nodes.First().IdCategoriaParente != null) { if (level > 0) { separatore = " >> "; } } if (level == 0) { /* @Html.DropDownList("Direction", new List<SelectListItem>{ new SelectListItem{ Text = "Home To School", Value = "0" }, new SelectListItem{ Text = "School To Home", Value = "1" }}, new { onchange = "getAlldata()" }) */ @Html.Raw("<select name="IdCategoriaParente" id="IdCategoriaParente">"); @Html.Raw("<option value="0">Nessuna</option>"); } foreach (var node in nodes) { if (node.Id == catfiglia) { selectRecord = "selected"; } //Funzioni.SelezionaSelect(node.Id, catfiglia) else { selectRecord = ""; } var fullText = accumulatore + separatore + node.NomeCategoria; @Html.Raw(string.Format("rn<option value="{0}" {2}>{1}</option>", node.Id, fullText, selectRecord)); @BuildTreeView(data, catfiglia, node.Id, level + 1, fullText); } if (level == 0) { @Html.Raw("rn</select>"); } } else { // @Html.Raw("<select name="IdCategoriaParente" id="IdCategoriaParente"><option value="0">Nessuna</option></select>"); }} It is working properly. The problem is that now, the result is printed on the screen with a select.I wish the result was made into a JSON format: {"...", "...", "...": ...}Can you help me?Thanks in advance Share this post Link to post Share on other sites
justsomeguy 1,093 Report post Posted June 22, 2015 Which language are you using there? The basic idea is to build the object or array structure you need, then use a function to convert that to a JSON string. Share this post Link to post Share on other sites