Search code examples
submenu

Re: Create Top and Side Menu


I am using ASP.NET MVC C# and am very new to programming and might get terminologies wrong.

After several online searches I am rather confused and would like some direction on how to get a new sub-menu to appear when I click on a menu-tab and how to have a side-bar menu to appear when I click on the sub-menu tab. In the image when a person clicks on "Employee" from the Top-Menu the below menu appears, How do I create this. And when "Employee List" is clicked the side-menu appears, How do i create this.

Image

Thanking for your help in advance.

Regards, Kyle


Solution

  • we can obviously not give you the exact code without knowing much more, but maybe you can include a MenuId parameter in your query string when a user has clicked on a menu item?

    And if the MenuId parameter is present in the query string, display a submenu?

    Your action in MVC could look like this, for instance:

    public IActionResult MyPage(int menuId)
    {
     ///your logic here
      var model = new Model();
      model.MenuId = menuId;
      return View(model);
    }
    

    and in your Razor View:

    @if (Model.MenuId.HasValue)
    {
        <ul>
         <li>This is my submenu</li>
         <li>Second menu item</li>
        </ul>
    }
    

    Does this help?