TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Olivier Muhring
NA
150
10k
Loading a menu structure on every razor page in asp .NET Core
Aug 28 2020 10:20 AM
After user authentication I'm supposed to change the user menu based on the roles of the user.
To do this, I created a service which fetched the menu the user is expected to see:
public
List<MenuStructure> LoadCompleteMenuRole(string role)
{
List<MenuStructure> resultList =
null
;
var menuHeaders = LoadMenuHeadersForTheGivenRole(role);
if (menuHeaders !=
null
&& menuHeaders.
Count
> 0)
{
resultList = new List<MenuStructure>();
foreach (var menuHeader
in
menuHeaders)
{
var menuStructure = new MenuStructure
{
MenuName = menuHeader.HeaderName,
Caption = menuHeader.Caption
};
var menuDetails = LoadMenuDetailsForTheGivenHeader(menuHeader.Id);
if (menuDetails !=
null
&& menuDetails.
Count
> 0)
{
menuStructure.MenuElements = new List<MenuElement>();
foreach (var menuDetail
in
menuDetails)
{
var menuElement = new MenuElement
{
ElementName = menuDetail.DetailName,
ElementCaption = menuDetail.Caption,
Destination = menuDetail.Destination
};
menuStructure.MenuElements.
Add
(menuElement);
}
}
resultList.
Add
(menuStructure);
}
}
return
resultList;
}
My problem? Where do I implement the service so the menus get loaded in every razor page I create?
Reply
Answers (
1
)
Asp.net mvc web api
How to convert Word docx to either Html or PDF from MVC application