Click here to Skip to main content
15,908,581 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to make menu in mvc view.I don't know how can i do this!!Is there anyone to help me?
I am a beginner....
Posted

 
Share this answer
 
The menu for the MVC application is defined in the file "Views" folder->"Shared" folder ->_Layout.cshtml file

If you open the file and browse it through you will see entries like

<nav>
    <ul id="menu">
        <li>@Html.ActionLink("Home", "Index", "Home")</li>
        <li>@Html.ActionLink("About", "About", "Home")</li>
        <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
    </ul>
</nav>



This is where you will defined your new menu and please google it, if you needs to know the parameter for
@Html.ActionLink



Hope this helps
 
Share this answer
 
create an entity class with menu and sub menu relalted logic, that work as model.

C#
public int Id { get; set; }
public string Name { get; set; }
public string Action { get; set; }
public string Controller { get; set; }
public List<Menu> SubMenu { get; set; }


In controller you have to add one method in your base class.This base class should be exectued by each and every pages of your application.

C#
public ActionResult MenuBar()
        {
            var menuItems = from t in dbContext.GetMenuItem(Session["LoggedInID"])
                            select t;

            return PartialView("Menubar", menuItems);

        }


create one basePage that inherited by every controller.

and then finally create one view that need to put in Layout.cshtml page.

@Html.Action("Menubar");

and In View you have to put loop for your model and will create relavant html to load your menu based on your desing.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900