Articles in this section

How to invoke controller method on ASP.NET Core Dropdown Menu item?

This knowledge base explains to invoke a controller method based on each menu item click to its respective action methods in ASP.NET Core Dropdown Menu.

It can be achieved by defining the “Url” in Items property. When we click the item that contains Url definition, it navigates to the corresponding controller action methods.

 

[CHTML]

 

 
<ejs-menu id="menu" items="ViewBag.menuItems"></ejs-menu>        

 

[CONTROLLER]

 

 public IActionResult Index()
    {
        // Menu items definition 
        List<MenuItem> menuItems = new List<MenuItem>(){
        new MenuItem
        {
            Text = "File",
            IconCss = "em-icons e-file",
            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" }
            }
        },
          
        new MenuItem { Text = "Help" }
        };
 
        ViewBag.menuItems = menuItems;
        return View();
    }
        
    public IActionResult Open()
{
        return View(); // Triggered for Open click
    }
    public IActionResult Save()
{
        return View(); // Triggered for Save click
    }
    public IActionResult Exit()
{
        return View();   // Triggered for Exit Click
    }
}
 

 

A complete working sample can be downloaded from Sample.

 

Note:

If you have facing any issue while running the sample, kindly use the latest package for EJ2 Assemblies.

 

 

 

Conclusion

I hope you enjoyed learning how to invoke controller method on ASP.NET Core Dropdown Menu item.

You can refer to our ASP.NET Core Dropdown Menu feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our  ASP.NET Core Dropdown Menu example to understand how to present and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied