Sidebar
Group and order the sidebar's items, and add links to your own pages
Introduction
When registering a resource, StellarAdmin adds an item to the sidebar, which links to the resource's index page. StellarAdmin allows full control over how these are registered, as well as registering links to other pages in your app, or external links.
Configuring a resource's sidebar item
To change a resource's sidebar item, call SidebarItem() on the resource builder. The example below moves the bookings into a Sales group, with a ticket icon, as the group's first item:
builder.Services.AddStellarAdmin(admin =>
{
admin.AddEfCoreResource<Booking>(resource =>
{
resource.SidebarItem(item =>
{
item.Group = "Sales";
item.Label = "All bookings";
item.Icon = "ticket";
item.Order = 1;
});
});
});

A sidebar item has the following members:
| Member | Description |
|---|---|
Group | Sets the label of the group the item is in. The default is "Resources". |
Label | Sets the item's label. The default is the resource's plural label. |
Icon | Sets the name of the icon displayed before the label. The default is none. |
Order | Sets the item's position in its group. See ordering the sidebar. |
Visible | Sets whether the item is in the sidebar. The default is true. |
StellarAdmin hides the item from users who aren't authorized to access the resource. Setting Visible to false only hides the item, but users can still open the resource's pages by their URL.
An item without an icon doesn't leave space for one, so the labels in a group only line up when every item in the group has an icon, or none has.
Adding links to your own pages
To add a link to one of your app's pages, call AddSidebarLink() with the link's label and a target. The example below links to a Razor Page and an MVC action in the Sales group, and to a help site in a new tab:
using StellarAdmin.Sidebar;
builder.Services.AddStellarAdmin(admin =>
{
admin.AddSidebarLink("Departures this week", SidebarLinkTarget.Page("/Admin/Departures"), link =>
{
link.Group = "Sales";
link.Icon = "calendar";
});
admin.AddSidebarLink("Invoices", SidebarLinkTarget.Action("Index", "Invoices"), link =>
link.Group = "Sales");
admin.AddSidebarLink("Help center", SidebarLinkTarget.Url("https://help.voyager.travel"), link =>
link.OpenInNewTab = true);
});

| Target | Links to |
|---|---|
SidebarLinkTarget.Page(page) | A Razor Page. To link to a page in an area, pass the area as well: Page(page, area). |
SidebarLinkTarget.Action(action, controller) | An MVC action. To link to an action in an area, pass the area as well: Action(action, controller, area). |
SidebarLinkTarget.Url(url) | An absolute URL, or a path in your app that starts with ~/. |
The link builder callback has the following members:
| Member | Description |
|---|---|
Group | Sets the label of the group the link is in. The default is null, which displays the link at the top level of the sidebar, without a group heading. |
Icon | Sets the name of the icon displayed before the label. The default is none. |
Order | Sets the link's position. See ordering the sidebar. |
OpenInNewTab | Sets whether the link opens in a new tab. The default is false. |
To display the page inside the admin panel, with the sidebar and the header, see custom pages.
When the page or the action of a target doesn't exist, StellarAdmin displays the link in red in the Development environment, with the reason, such as "No page /Admin/Reports". In other environments, it hides the link and logs a warning.


Hiding a link from certain users
To hide a link from users who don't meet an authorization requirement, call RequireAuthorization() on the link. It takes the same arguments as the resource's RequireAuthorization(). The example below displays the Invoices link only to people in the Finance role:
builder.Services.AddStellarAdmin(admin =>
{
admin.AddSidebarLink("Invoices", SidebarLinkTarget.Action("Index", "Invoices"), link =>
link.RequireAuthorization(policy => policy.RequireRole("Finance")));
});RequireAuthorization() only hides the link from the sidebar. To prevent users from opening the page, add [Authorize] to the page or the controller.
Ordering the sidebar
StellarAdmin displays the sidebar's items in the order you add them, so adding your resources and links in the order you want is usually enough. Resources and links with the same Group share a group.
Items with an Order appears before the items without one, with the lowest Order first. A resource's Order sets its position in its group. A link's Order sets its position in its group.
To move a group, or to sort its items by label, call ConfigureSidebarGroup() with the group's label. The example below displays the Catalog group first and the Sales group second, and sorts the items in the Settings group by label:
builder.Services.AddStellarAdmin(admin =>
{
admin.ConfigureSidebarGroup("Catalog", group => group.Order = 1);
admin.ConfigureSidebarGroup("Sales", group => group.Order = 2);
admin.ConfigureSidebarGroup("Settings", group => group.SortItemsByLabel = true);
});ConfigureSidebarGroup() doesn't add a group. The group is displayed when a resource or a link is in it.
To sort every group and every item by label, call ConfigureSidebar() and set SortGroupsByLabel and SortItemsByLabel:
builder.Services.AddStellarAdmin(admin =>
{
admin.ConfigureSidebar(sidebar =>
{
sidebar.SortGroupsByLabel = true;
sidebar.SortItemsByLabel = true;
});
});Sorting by label only applies to the items and groups without an Order, and are positioned after the items with an Order.
Adding dynamic sidebar items
Normally you register sidebar items in the StellarAdmin configuration. However, sometimes you may want to add items to the sidebar that are not known ahead of time and are generated dynamically, for example, from a database. You can do this by adding a class that implements ISidebarItemsProvider and return the items from the GetItemsAsync() method.
The example below adds a Featured trips group, with a link to the edit page of each of the first 3 published trips:
using StellarAdmin.Sidebar;
public class FeaturedTripsSidebarItemsProvider(ApplicationDbContext db) : ISidebarItemsProvider
{
public async Task<IReadOnlyList<SidebarItem>> GetItemsAsync(
HttpContext httpContext, CancellationToken cancellationToken)
{
var trips = await db.Trips
.Where(trip => trip.IsPublished)
.OrderBy(trip => trip.Title)
.Take(3)
.ToListAsync(cancellationToken);
return
[
new SidebarGroupItem(
"Featured trips",
trips.Select(trip => new SidebarLinkItem(trip.Title, $"~/stellaradmin/trips/edit/{trip.Id}")
{
Icon = "plane",
})),
];
}
}Register the FeaturedTripsSidebarItemsProvider with dependency injection:
builder.Services.AddScoped<ISidebarItemsProvider, FeaturedTripsSidebarItemsProvider>();You can return the following types from GetItemsAsync():
| Type | Description |
|---|---|
SidebarGroupItem(label, items) | A group of links. Its items join the group with the same label, if there is one. |
SidebarLinkItem(label, href) | A link to an absolute URL, or a path in your app that starts with ~/. |
SidebarPageLinkItem(label, page, area) | A link to a Razor Page. Pass "" as the area for a page without an area. |
SidebarActionLinkItem(label, controller, action, area) | A link to an MVC action. Pass "" as the area for an action without an area. |
A link that isn't inside a SidebarGroupItem is displayed at the top level of the sidebar. The items from a provider come after the items you added in AddStellarAdmin(), unless they have an Order.
Your sidebar items provider will be called every time the sidebar is rendered (i.e. for every page), so keep it fast, and consider implementing some sort of caching if necessary.
If links need to be available only to certain users, you need apply the logic for this yourself inside the GetItemsAsync method. You can access the current user from the httpContext parameter.