I have explained below for creating a sample menu structure dynamically.
Create a class and add a property for storing li structure.If u need UI collection declare this too.
public class Menu
{
public List<string> li{get;set;}
}
Create an ActionResult
public ActionResult Index()
{
var menu=new Menu();
menu.li=Loadli();
return view();
}
public List<string> LoadUl()
{
var list=List<string>();
list.Add("Home");
list.Add("ASP.NET");
}
Create a view which return Menu.If you are using anyother class then declare the li property on that class and loop through the item according to your structure.
@model Menu
{
<ul>
@foreach (var item in Model.li)
{
<li>@item</li>
}
</ul>
}
Hope this helps