I'm new to ASP.NET Core MVC, and trying to create a simple website. So, now I'm trying to reach my navigation bar items from another controller.
This is my MenuController
:
private static List<Menu> GetMenus()
{
List<Menu> menu = new()
{
new Menu { MenuId = 1, MenuName = "Elektronik" },
new Menu { MenuId = 2, MenuName = "Moda" },
new Menu { MenuId = 3, MenuName = "Ev Tekstil" },
new Menu { MenuId = 4, MenuName = "Outdooe" }
};
return menu;
}
public List<AltMenu> GetAltMenus()
{
List<AltMenu> altMenus = new()
{
new AltMenu { AltMenuId = 1, AltMenuName = "Televizyon", AnaMenuId = 1 },
new AltMenu { AltMenuId = 2, AltMenuName = "Giyim", AnaMenuId = 2 },
new AltMenu { AltMenuId = 3, AltMenuName = "Alt Menu", AnaMenuId = 2 },
new AltMenu { AltMenuId = 4, AltMenuName = "Alt Menu", AnaMenuId = 3 },
new AltMenu { AltMenuId = 5, AltMenuName = "Alt Menu", AnaMenuId = 3 },
new AltMenu { AltMenuId = 6, AltMenuName = "Alt Menu", AnaMenuId = 4 }
};
return altMenus;
}
public ExpandoObject GetAllMenu()
{
dynamic mymodel = new ExpandoObject();
mymodel.Menu = GetMenus();
mymodel.AltMenu = GetAltMenus();
TempData["Menu"] = mymodel;
return RedirectToAction("Index", "Home", TempData["Menu"]);
}
Trying to reach this from HomeController
(or another). So I can use my menu navbar in different pages without database.
PS.: I'm getting an error at the "return" line:
CS0029 Cannot implicitly convert type 'Microsoft.AspNetCore.Mvc.RedirectToActionResult' to 'System.Dynamic.ExpandoObject'