I have a demo project in which i have rendered a menu dynamically from database using Entity Model I have Add a Model into my Models Folder and in this model i have my menu table (id,parentId,title)
then i have made a menu controller like that
private TestEntities testEntities = new TestEntities();
public ActionResult Index()
{
ViewBag.MenuLevel1 = this.testEntities.Menus.Where(menu=>menu.ParentId==null ).ToList();
return View();
}
and in my View--->Menu--->index i have that code
@Model Menu.ModelTest
@foreach (var menuLevel1 in ViewBag.MenuLevel1)
{
@if (menuLevel1.Child.Count > 0)
{
@foreach (var menuLevel2 in menuLevel1.Child)
{
@menuLevel2.Name
}
}
}
Basically i am newby in MVC i want the layout file just like a master page in asp.net and i want the menu to be dynamic in this layout file. any help please

Shakti Singh DulawatRank #668 · 3.6K reputationPosted May 11, 2016, 8:08 AM EDT
$hakti $ingh
Mark TaborRank #914 · 2.3K reputationPosted May 11, 2016, 11:47 AM EDT