Jump to content

Converto Output to Json


AspNetx

Recommended Posts

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...