Jump to content

AspNetx

Members
  • Content count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral

About AspNetx

  • Rank
    Newbie
  1. Converto Output to Json

    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
×