ok I Want Load Main Menu of MySite Dynamically With SqlServer DataBase.
my project is "asp.net core razor page"
I using ComponentView for MainMenu.
I use Service to load mainmenu
this is IMainMenuService Code:
namespace WebApplication4.Utilities.Services.MainMenu
{
public interface IMainMenuService
{
List<MainMenuTable> GetAllMenu();
}
public class MainMenuService : IMainMenuService
{
public List<MainMenuTable> GetAllMenu()
{
return new List<MainMenuTable>()
{
new MainMenuTable() {Link = "link1", Title = "عنوان1"},
new MainMenuTable() {Link = "link2", Title = "عنوان2"},
new MainMenuTable() {Link = "link3", Title = "عنوان 3"},
new MainMenuTable() {Link = "link4", Title = "عنوان 4"}
};
}
}
this is _Layout file:
@await Component.InvokeAsync("MainMenuComponent")
this is MainMenuComponent:
<pre>namespace WebApplication4.Pages.Shared.Components
{
public class MainMenuComponent : ViewComponent
{
private IMainMenuService _mainMenuService;
public MainMenuComponent(IMainMenuService mainMenuService)
{
_mainMenuService = mainMenuService;
}
public async Task<IViewComponentResult> InvokeAsync()
{
return View("/Pages/Shared/Components/_MainMenu.cshtml", _mainMenuService.GetAllMenu());
}
}
}
Now i Want to Return MainMenuTable Rows in
public List<MainMenuTable> GetAllMenu()