Rewrite Data from an Object List in HTML

Asked

Viewed 39 times

0

Hello, I have a List of objects that is being created in an Onget method and I need to get all the data from it to put in my html page, as I can recover this data?

List<string> MenuPrincipal = new List<string>();
int i = 1;
while (result.vfp.row[i].men == "_MSYSMENU")
{
    MenuPrincipal.Add(result.vfp.row[i].des);
    i++;
}

It has string values, I’ve checked it... as for example, the MenuPrincipal[0], has value exemplo. And the MenuPrincipal[1], has value exemplo2.

Anyway, I need to get the exemplo, is an item from my menu in the navigation bar and the exemplo2, be another item of this same bar, and from them will come a submenu that will be filled in the same way, but later.

Help me please, thank you.

  • You need to go into more detail what you want. You want to turn each item of this List<string> into an html menu option?

  • Exactly @iamdlm

1 answer

0

To convert a string list to an HTML list you can use the following method (no recursiveness):

private void BuildList(List<string> menu)
{
    StringBuilder sb = new StringBuilder();
    sb.Append("<ul>");
    foreach (string item in menu)
    {
        sb.Append("<li>" + item + "</li>");                
    }
    sb.Append("</ul>");
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.