What I did for the menu and other navigational elements is that I have a ViewModel class. Here is a simplified version.
ViewModel
public class Action { public string DisplayName { get; set; } // localized public string Url { get; set; } public class MenuViewModel { public List<Action> Actions { get; set; } public MenuViewModel() { this.Actions = new List<Action>(); } }
I fill this out depending on the role of the user. Admin gets more links, etc.
This ViewModel is part of the "core" view model.
public class AlbumEditorViewModel { public MenuViewModel Menu { get; set; } }
Then I will pass this view model for a partial view that is responsible for the menu.
Preview (Razor)
@model AlbumEditorViewModel .. razor stuff here .. @Html.Partial("Menu", Model.Navigation) .. razor stuff here ..
Partial view
@model MenuViewModel <ul> @foreach (var action in Model.Actions) { <li> @GridHelper.GetAction(action) </li> } </ul>
I hope this gives you ideas.
source share