We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Try to create a menu as a partial load in the _layout based on data in a database but it doesn't show the menu.

I have the following partial view:
@model StudentUnion0105.Controllers.PartialController
    <div class="menu-control"><ejs-menu id="menuInTop" items="ViewBag.menuItems2"></ejs-menu></div>

The following script in the _Layout:

and the following div in the _Layout:
    <div id="TopMenu"></div>

The controller for the partial view is:
        public async Task<IActionResult> TopMenu()

            var CurrentUser = await userManager.GetUserAsync(User);
            var DefaultLanguageID = CurrentUser.DefaultLanguageId;

            var parameter = new SqlParameter("@LanguageId", DefaultLanguageID);

            var TopMenu1List = _context.ZdbTopMenu1.FromSql("PartialTopMenu1 @LanguageId", parameter).ToList();

            List<MenuItem> menuItem1List = new List<MenuItem>();
            foreach (var TopMenu1 in TopMenu1List)
                menuItem1List.Add(new MenuItem
                    Text = TopMenu1.MenuName,
                    IconCss = TopMenu1.IconCss,
                    Url = TopMenu1.MenuController,
                    Items = new List<MenuItem>()
                    new MenuItem { Text= "Open", IconCss= "em-icons e-open", Url= "Home/Open" },
                    new MenuItem { Text= "Save", IconCss= "e-icons e-save", Url= "Home/Save" },
                    new MenuItem { Separator= true },
                    new MenuItem { Text= "Exit", Url= "Home/Exit" }


using Syncfusion.EJ2.Navigations;

First level of the menu is coming from the database, second level for testing is hardcoded.

Further, when I debug on the partial view:
            ViewBag.menuItems2 = menuItem1List;
            return PartialView();

I see that the viewbag will have values. See image attached.

I did all kind of scenarios Some getting more results than others but no menu. (some had the div tag from the partial view.). At one time I had a UL tag but no IL.

Any suggestions what to do?



Attachment: ViewBag_d9ff57b9.zip

4 Replies

AD Arunkumar Devendiran Syncfusion Team January 22, 2020 06:36 PM UTC

Hi Peter, 
Thank you for contacting Syncfusion support. 
We have created the sample for your reported query in that we have add the our menu component in Partial_View.cshtml (Views/Home) and by referring <partial name="../Home/Partial_View.cshtml"/> tag in layout page we have achieved your requirement. Could you please check the below sample and let us know whether this is fulfilling your requirement, if not please share us more information regarding this. If possible, please replicate your issue in below sample and revert to us. So, that we can analyze based on that and provide you a better solution. The information provided would be great help for us to proceed further. 
Sample Link: 
Arunkumar D 

PE Peter January 23, 2020 09:17 AM UTC

Hi Arunkumar,

I will check it out and let you know.

Thanks very much.


PE Peter January 23, 2020 09:57 AM UTC

Hi Arunkumar,

Thanks for the sample, I got it working now also in my environment. I am really impressed by the support from SyncFusion. By the way, I am building an platform for communities who want to improve the environment / sustainability.

Kind regards,


SD Saranya Dhayalan Syncfusion Team January 23, 2020 11:13 AM UTC

Hi Peter 
We are glad that our sample worked in your environment. 
Saranya D 

Live Chat Icon For mobile
Up arrow icon