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
Mark TaborPosted May 11, 2016, 3:47 PM
Shakti Singh DulawatPosted May 11, 2016, 12:08 PM
$hakti $ingh