Dynamic menu from database

后端 未结 1 1135
南旧
南旧 2020-12-07 05:43

I have a Login page where on login it takes user to Home Page where dynamic menu is loaded.The problem is that when a user clicks on

相关标签:
1条回答
  • 2020-12-07 06:35

    Create a separate [ChildActionOnly] method that generates your menu and call it from the layout page so its available in all pages

    [ChildActionOnly]
    public ActionResult Menu()
    {
      var model = new DashboardVM
      {
         ....
      }
      return PartialView("_Menu", model);
    }
    

    and create a _Menu.cshtml partial view to generate the html

    @model DashboardVM
    ....
    

    and then in your layout, remove @model SMS.Models.ViewModel.DashboardVM (a layout should not have a model unless that model is a base class for all models used by the layout) and then include

    @Html.Action("Menu", yourControllerName)
    

    which will call the Menu method and insert the partial view it returns into the layout.

    0 讨论(0)
提交回复
热议问题