How To
9 Apr 2018 / 2 minutes to read
Render Menu from code behind
Menu can be rendered from the code behind by initializing the required properties in controller and passing those properties via ViewData or Model to the client side
The following code illustrates the rendering of Menu using Menu properties from code behind.
@{
Html.EJ().Menu("Menu", (Syncfusion.JavaScript.Models.MenuProperties)ViewData["Menu"]).Render();
}
public ActionResult Index()
{
List<MenuBaseItem> obj = new List<MenuBaseItem>();
obj.Add(new MenuBaseItem() { Text="Products"});
obj.Add(new MenuBaseItem() { Text = "Support" });
obj.Add(new MenuBaseItem() { Text = "Downloads" });
obj.Add(new MenuBaseItem() { Text = "Purchase" });
obj.Add(new MenuBaseItem() { Text = "Resources" });
obj.Add(new MenuBaseItem() { Text = "Company" });
MenuProperties menu = new MenuProperties();
menu.Items = obj;
menu.Width = "150";
menu.Orientation = Syncfusion.JavaScript.Orientation.Vertical;
ViewData["Menu"] = menu;
return View();
}
Was this page helpful?
Yes
No
Thank you for your feedback!
Thank you for your feedback and comments. We will rectify this as soon as possible!
An unknown error has occurred. Please try again.
Help us improve this page