Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Post
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Reply
MVc dynamic Menu using Partial View
Mark Tabor
May 12 2016 5:04 AM
1.4k
Reply
I have made a simple Dynamic MVC menu application in which i have an entity model and i bind this entity model from database table {Menu table} , I have created a simple MVC application in which it automatically add home controller and i wrote the below c0de in home controller
private TestEntities testEntities = new TestEntities();
public ActionResult Index()
{
ViewBag.MenuLevel1 = this.testEntities.Menus.Where(menu=>menu.ParentId==null ).ToList();
return View();
}
Secondly I have Menu Folder Under Views and in this Menu folder i have index view and my index view is just look like that
@model Menu.Models.Menu
<ul>
@foreach (var menuLevel1 in ViewBag.MenuLevel1)
{
<li>@menuLevel1.Name
@if (menuLevel1.Child.Count > 0)
{
<ul>
@foreach (var menuLevel2 in menuLevel1.Child)
{
<li>
@menuLevel2.Name
</li>
}
</ul>
}
</li>
}
</ul>
Now i want to make this Menu item as partial view and want to call it from _LAyout.cshtml how to do that ? i have check lot of example non of them makes me happy :)
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Using VC++ MFC diaglog to retrieve data from database:
fix a time and date to fill and edit the gridview and save ?